i am working on project .
i have two sensor "button 1" and "button".when button 1 will activate it will turn on led1 for 1000 mili seconds and led 2 will be off during this.
and if button 2 activate it will turn on led 2 for 1000 msec and led1 will be off for same time.
i am having the error" button state2 was not declared in this scope highlight on the this line " buttonState1 = digitalRead(buttonPin1);"
const int buttonPin1 = 2; // the number of the pushbutton pin 2
const int buttonPin2 = 3; // the number of the pushbutton pin 3
const int ledPin1 = 13; // the number of the LED pin
const int ledPin2 = 12;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
// read the state of the pushbutton value:
buttonState2= digitalRead(buttonPin2);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
// turn LED on:
digitalWrite(ledPin1, HIGH);
delay(1000);
digitalWrite(ledPin2, LOW);
delay(1000);
if
(buttonState2 == HIGH) {
// turn LED on:
digitalWrite(ledPin2, HIGH);
delay(1000);
digitalWrite(ledPin1, LOW);
delay(1000);
}
}
}