Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: ap16 on Feb 13, 2018, 03:37 am

Title: how can i use input_pullup
Post by: ap16 on Feb 13, 2018, 03:37 am
I want to setup 2 switches and 3 leds. When switch 1 is pressed an led(red) comes on and when switch 2 is pressed another led(green) comes on. Then when switch 1 and switch 2 are both pressed all the leds come on(white).
Title: Re: how can i use input_pullup
Post by: larryd on Feb 13, 2018, 04:05 am
Show us what you have done.

Show us a good schematic of your circuit. 
Show us a good image of your wiring.

Always show us your 'current' compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.   
[code] Paste sketch here. [/code]

Title: Re: how can i use input_pullup
Post by: CrossRoads on Feb 13, 2018, 04:38 am
Here are basics, see if you can work it out:

pinMode (pin2, INPUT_PULLUP);
pinMode (pin3, INPUT_PULLUP);

pin2state = digitalRead (pin2);
pin3state = digitalRead(pin3);

if (pin2state == LOW && pin3state == LOW){
// do one thing
}

if (pin2state == HIGH && pin3state == LOW){
// do one thing
}

if (pin2state == LOW && pin3state == HIGH){
// do one thing
}

if (pin2state == HIGH && pin3state == HIGH){
// do one thing
}
Title: Re: how can i use input_pullup
Post by: ap16 on Feb 13, 2018, 04:33 pm
Show us what you have done.

Show us a good schematic of your circuit. 
Show us a good image of your wiring.

Always show us your 'current' compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.   
[code] Paste sketch here. [/code]


Show us what you have done.

Show us a good schematic of your circuit. 
Show us a good image of your wiring.

Always show us your 'current' compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.   
[code] Paste sketch here. [/code]


here is my circuit https://imgur.com/a/Zzq7r
Title: Re: how can i use input_pullup
Post by: larryd on Feb 13, 2018, 04:47 pm
(https://i.imgur.com/uWOHJ2u_d.jpg?maxwidth=640&shape=thumb&fidelity=medium)

Show us your current sketch also.




Title: Re: how can i use input_pullup
Post by: larryd on Feb 13, 2018, 04:51 pm
If you push switch #1 then let go, does the red LED follow the switch?

Do red and green come on if both switches are pushed?

What is this to be used for?


Title: Re: how can i use input_pullup
Post by: ap16 on Feb 14, 2018, 02:54 am
Here are basics, see if you can work it out:

pinMode (pin2, INPUT_PULLUP);
pinMode (pin3, INPUT_PULLUP);

pin2state = digitalRead (pin2);
pin3state = digitalRead(pin3);

if (pin2state == LOW && pin3state == LOW){
// do one thing
}

if (pin2state == HIGH && pin3state == LOW){
// do one thing
}

if (pin2state == LOW && pin3state == HIGH){
// do one thing
}

if (pin2state == HIGH && pin3state == HIGH){
// do one thing
}
thanks for that but i'm not getting a light I used digitalWrite
Title: Re: how can i use input_pullup
Post by: larryd on Feb 14, 2018, 02:59 am
Quote
thanks for that but i'm not getting a light I used digitalWrite
Always show us your 'current' compete sketch.
Use CTRL T to format the sketch. Please use code tags.
Use the </> icon in the posting menu. 
 [code] Paste sketch here. [/code]
Title: Re: how can i use input_pullup
Post by: Grumpy_Mike on Feb 14, 2018, 08:52 am
Quote
thanks for that but i'm not getting a light I used digitalWrite
You did replace the lines
Quote
// do one thing
With a line of code that actually did something like turn your light on?

You need to write a LOW to turn on your light.