Hi, everyone.
i am new to arduino and i like amazing projects, then i try to make one for my self.
i want to Read 2 inputs at a time and make OUTPUT to work correctly.
i write this code in IDE. anyone plz help me if there is a problem in my coding.
(Note: i want if 1 input is high the 1 led ON, if 2nd input high and first input low then both leds OFF, if both input high then 2nd led ON. )
int btn1 = A1;
int btn2 = A4;
int led = 3;
int led2 = 6;
When posting source code please use the </> button above and past your code there. This makes the code easier to read and copy. It should look like this:
thankyou Both of you for the suggestion . digitalRead work for me... i change my code But this time i write both LOW LOW, but it turn HIGH both leds once. any suggestion.
thankyou Both of you for the suggestion . digitalRead work for me... i change my code But this time i write both LOW LOW, but it turn HIGH both leds once. any suggestion??
Buttons are normally wired to gnd and have input-pullup in the code initialisation.
Look at your if statements and follow the logic. You need to write what you want.
Your first if says that if button 1 is pressed then high. It says nothing about if button 2 is pressed. Code runs through and doesn’t care about anything other than the instructions given. If button 1 is pressed it will go high irrespective of what else is pressed.
Use a multi conditional statement
Btn1 == 1 && btn2 ==0
Pseudocode use correct syntax
Ps is this a homework assignment. Recent similar posts
Think about your code and what it does. If you need to read btn1 then you also need to read btn2. The microcontroller is pedantic and will do exactly as it says so don’t take shortcuts