pls fix this coding
the problem is when I push button 2 the led 1 and led 2 light up at the same time
it was suppose to be when push button 1 is pushed, Led 1 ON.When push button 2 is pushed,Led 2 ON. When push button 3 is pushed,Led 3 ON.
Here's the coding below:
const int LED1 = 2;
const int LED2 = 3;
const int LED3 = 4;
//Variables
int buttonValue; //Stores analog value when button is pressed
void setup()
{
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
void loop()
{
buttonValue = analogRead(A1); //Read analog value from A0 pin
//For 1st button:
if (buttonValue>=670 && buttonValue<=690){
digitalWrite(LED1, HIGH);
}
//For 2nd button:
else if (buttonValue>=500 && buttonValue<=520){
digitalWrite(LED2, HIGH);
}
//For 3rd button:
else if (buttonValue>=-10 && buttonValue<=10){
digitalWrite(LED3, HIGH);
}
//No button pressed, turn off LEDs
else{
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
}
}
U can test the coding in Proteus in picture above
T LED-BIBY PREBEREE. D1 28 38. R1 R5 RD RA Ⓒ GUT 1 -O OUT 2 OUT 3
pls fix this coding the problem is when I push button 2 the led 1 and led 2 light up at the same time it was suppose to
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am