Add project code

This commit is contained in:
Anthony Wang 2022-11-10 17:00:55 -05:00
parent 18f0991486
commit 53d80d02eb
Signed by: a
GPG key ID: 42A5B952E6DD8D38

22
project/project.ino Normal file
View file

@ -0,0 +1,22 @@
#include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(0); // attach to pin 0
analogReadResolution(8);
}
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
}
}
}