im try to make an led to turn on when the switch is pressed for 1 time and then turn off and when thbe switch is pressed again another led is switched offf can someone tell me what is wrong in my above code to perform this.
const int buttonPin = 2;
const int led = 7;
const int led1 = 8;
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(led, OUTPUT);
pinMode(led, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
digitalWrite(led, LOW);
digitalWrite(led1, LOW);
buttonState = digitalRead(buttonPin);
int buttonState1 = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(led, HIGH);
delay(5000);
}
buttonState == LOW;
if(buttonState1 == HIGH){
digitalWrite(led1, HIGH);
delay(5000);
}
}
Moderator edit: CODE TAGS