blob: 085522385cb56d67c0992385477fb6ed7efbd336 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
#include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(0); // attach to pin 0
analogReadResolution(8);
myservo.write(180);
}
void loop() {
if (analogRead(A0) > 180) {
for (int pos = 180; pos >= 0; pos -= 5) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int pos = 0; pos <= 180; pos += 5) { // 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
}
}
}
|