Add project code
This commit is contained in:
parent
18f0991486
commit
53d80d02eb
22
project/project.ino
Normal file
22
project/project.ino
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue