diff options
author | Anthony Wang | 2022-11-10 17:00:55 -0500 |
---|---|---|
committer | Anthony Wang | 2022-11-10 17:00:55 -0500 |
commit | 53d80d02eb99feceeef145ef3471e0fd2d58d432 (patch) | |
tree | 57aeaf67445cf6bb8724a1ce74d8be6f7a83573e | |
parent | 18f0991486d9a81e23eb6575427a2bd4f97c3de7 (diff) |
Add project code
-rw-r--r-- | project/project.ino | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/project/project.ino b/project/project.ino new file mode 100644 index 0000000..d613756 --- /dev/null +++ b/project/project.ino @@ -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 + } + } +} |