6.A01/project/project.ino
2022-11-17 17:18:40 -05:00

24 lines
759 B
C++

#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
}
}
}