Hi,
I was trying to make a servo turn 90 degrees when I pressed a button and then go back to start when I pressed it again. I¨m new to Arduino and programming so I didn't know exactly how to deal with variables. It goes to 0 when I start it and to 90 when I press the button, but nothing happens when I press it again.
#include <Servo.h>;
int pos = 0; // Start position
int laas = 0; // 0 = Gate down
// pushbutton pin
const int buttonPin = 8;
// servo pin
const int servoPin = 7;
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()
{
// local variable to hold the pushbutton states
int buttonState;
//read the digital state of buttonPin with digitalRead() function and store the //value in buttonState variable
buttonState = digitalRead(buttonPin);
//if the button is pressed increment counter and wait a tiny bit to give us some //time to release the button
if (buttonState == LOW) // If button is pressed
{
if (laas = 1){
laas = 0;
servo.write(pos); // Go to start position
delay(50);
}
if (laas = 0) {
laas = 1;
servo.write(90); // Go Down
delay(50);
}
}
}