2019-04-14 23:11:37 +02:00

25 lines
864 B
C++

#include <Servo.h>
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
void setup() {
myservo.attach(2); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo.write(0); // tell servo to go to position in variable 'pos'
delay(1000); // waits 15ms for the servo to reach the position
myservo.write(180); // tell servo to go to position in variable 'pos'
delay(1000);
/* Example:
for (pos = 2200; pos >= 800; pos -= 20) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 15ms for the servo to reach the position
}*/
}