#include <Servo.h>
Servo myservo; // create servo object to control a servo
const int ServoPin = 9;
const int ButtonPin = 8;
byte flag = 0;
void setup()
{
pinMode(ButtonPin, INPUT_PULLUP);
myservo.attach(ServoPin); // attaches the servo on pin 9 to the servo object
}
void loop()
{
static unsigned long lastTime = 0;
static unsigned char lastButton = HIGH;
if (millis() - lastTime > 30) {
unsigned char theButton = digitalRead(ButtonPin);
if (theButton != lastButton) {
lastButton = theButton;
if (!theButton) flag++;
lastTime = millis();
}
}
while (flag == 1)
{
for (int pos = 0; pos < 180; pos ++) // 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
}
flag = 2;
}
while (flag == 3)
{
for (int pos = 180; pos > 0; pos--) // 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
}
flag = 0;
}
}
uno:A5.2
uno:A4.2
uno:AREF
uno:GND.1
uno:13
uno:12
uno:11
uno:10
uno:9
uno:8
uno:7
uno:6
uno:5
uno:4
uno:3
uno:2
uno:1
uno:0
uno:IOREF
uno:RESET
uno:3.3V
uno:5V
uno:GND.2
uno:GND.3
uno:VIN
uno:A0
uno:A1
uno:A2
uno:A3
uno:A4
uno:A5
servo1:GND
servo1:V+
servo1:PWM
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r