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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

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

Post by answerhappygod »

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);
}
}
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 1
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 1 (90.13 KiB) Viewed 28 times
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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply