/* Sweep by BARRAGAN This example code is in the public domain. modified 8 Nov 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Sweep */ #include #include #define PIN_INPUT 0 #define PIN_OUTPUT 3 //Define Variables we'll be connecting to double Setpoint, Input, Output; //Specify the links and initial tuning parameters double Kp=2, Ki=5, Kd=1; PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT); Servo myservo; // create servo object to control a servo // twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position int dif = 30; void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object myservo.write(90); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } void loop() { for (pos = 90; pos <= 90+dif; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } // myservo.write(90+dif); // tell servo to go to position in variable 'pos' // delay(70); // myservo.write(90); // tell servo to go to position in variable 'pos' // delay(500); // waits 15ms for the servo to reach the position }