From 53d80d02eb99feceeef145ef3471e0fd2d58d432 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 10 Nov 2022 17:00:55 -0500 Subject: Add project code --- project/project.ino | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 project/project.ino 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 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 + } + } +} -- cgit v1.2.3-70-g09d2