#include <Servo.h>;
// pushbutton pin
const int buttonPin = 2;
// servo pin
const int servoPin = 9;
Servo servo;
//create a variable to store a counter and set it to 0
int counter = 0;
void setup()
{
servo.attach (servoPin);
// Set up the pushbutton pins to be an input:
pinMode(buttonPin, INPUT);
}
void loop()
{
int buttonState;
buttonState = digitalRead(buttonPin);
if (buttonState == LOW) // light the LED
{
counter++;
delay(150);
}
if(counter == 0)
{
servo.write (0);
}
else if(counter == 1 )
{
servo.write (180);
}
else
{
counter = 0;
}
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.