I am creating a simple Arduino push button program. The idea is that if you press one button the LED will blink and if you press the other button the LED will just turn on. If you press both buttons the LED will turn off. I have been trying to compile the code and the error message is 'button1state' was not declared in this scope. Here is the code.
const int button1Pin = 2; // pushbutton 1 pin
const int button2Pin = 3; // pushbutton 2 pin
const int ledPin = 13; // LED pin
void setup()
{
pinMode(button1Pin, INPUT);
pinMode(button2Pin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop()
{
int button1State, button2State; // variables to hold the pushbutton states
button1State = digitalRead(button1Pin);
button2State = digitalRead(button2Pin);
if (button1State == LOW && ! (button1State == LOW && button2State == LOW))
{
digitalWrite(ledPin, HIGH); // turn the LED on
}
if (button2State == LOW && ! (button2state== LOW && button1state== LOW))
{
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin,LOW);
}
if(button2state==LOW && button1state== LOW)
{
digitalWrite(ledPint,LOW);
}
}