Go Down

Topic: Silly question about Examples in Arduino Enivronment (Read 538 times) previous topic - next topic

MiB1986

Dear All,

A real numpty question,

The examples in the Arduino environment, Button and Debounce,

I have connected a push to make switch to the board as described and checked with the DigitalReadSerial example. So i am getting logic level 1 and 0.

Am i right in saying, that when the button is pushed the LED should remain on all the time the button is pushed? and then as soon as you release the button, it should turn the LED off.

OR

Do you push the button once for ON and once for OFF

Please can someone confirm
Thanks
Martyn

Please can someone confirm as i am concerned I've done something wrong.



CrossRoads

I think the code can be written for either.
Press & hold for one level, or press & release for a state change (1-0, 0-1) with every button press.
I've not used either example personally, but written similar functionality into my code,
usually performing some action when I detect a low (button pressed to ground a pin that has internal pullup enabled) and if the ensuing code is too quick, adding a slight delay for debug.
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.

Nick Gammon


Please can someone confirm as i am concerned I've done something wrong.


Test it and see? If it doesn't do what you expect:


  • Tell us what you expect

  • Tell us what actually happens

  • Post your code

  • Show your wiring

Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Brad Burleson


Am i right in saying, that when the button is pushed the LED should remain on all the time the button is pushed? and then as soon as you release the button, it should turn the LED off.


Sounds exactly right to me.  The Button example clearly only will illuminate the LED when the button reads HIGH.

The Debounce example has misleading comments - the comments imply the LED only changes when the state goes LOW to HIGH when in reality any time the state changes from the previous (after 10 millis anyways) the LED will change state as well.

So in effect the Debounce example is just a different way of doing the same thing. 

I hope this helps,

Brad (KF7FER)

Go Up