Go Down

Topic: how can i use input_pullup  (Read 198 times) previous topic - next topic

ap16

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).

larryd

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]

No technical PMs.
The last thing you did is where you should start looking.

CrossRoads

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
}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

ap16

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

larryd



Show us your current sketch also.




No technical PMs.
The last thing you did is where you should start looking.

larryd

#5
Feb 13, 2018, 04:51 pm Last Edit: Feb 13, 2018, 04:54 pm by larryd
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?


No technical PMs.
The last thing you did is where you should start looking.

ap16

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

larryd

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]
No technical PMs.
The last thing you did is where you should start looking.

Grumpy_Mike

#8
Feb 14, 2018, 08:52 am Last Edit: Feb 14, 2018, 08:53 am by Grumpy_Mike
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.

Go Up