#include <Servo.h>
Servo servo;
int pb =8;
int pb_state=HIGH;
bool move=false;
int angle =0;
int direction=1;
void setup() {
// put your setup code here, to run once:
pinMode(pb, INPUT_PULLUP);
servo.attach(11);
}
void loop() {
// put your main code here, to run repeatedly:
pb_state= digitalRead(8);
if(pb_state==LOW){
move=!move;
while (digitalRead(pb) == LOW)
{
}
}
if(move){
if(angle>180){
angle=180;
direction=-1;
}
if(angle<0){
angle=0;
direction =1;
}
angle +=direction;
servo.write(angle);
}
delay(5);
}