pushbutton

17 Mar 2011

Hi evryone,

I am in the process of designing a PCB which have LCD, SD card, USB RJ45_poe and one input. Now I need to add 2 push buttoms in the circuit but don't know how to connect it. Can anyone please help me.

Regards

Sandee

17 Mar 2011

Push buttons must be conected to DigitalIn pins. DigitalIn have internal pull-down resistors so all you have to do is wire the push buttons from DigitalIn to 3v3 or 5v. You may add stronger pull-downs by wiring from the same DigitalIn pins resitors to GND (10k-100k).

Titi

17 Mar 2011

There is a way to connect more than one button to one (analog)input pin. I use 4 push buttons on p15. Works great. Read next document for instructions. http://www.freescale.com/files/microcontrollers/doc/app_note/AN1775.pdf

17 Mar 2011

You can also use the internal pull-up by setting that mode. Then simply connect the mbed pin to one side of the switch and the other to 0v. However, then the switch "open" (not pressed) makes the pin read as 1 and pressing the switch makes the pin read as 0 (the sense is inverted).

Once you have connected your pushbutton or switch you have to write the code to handle it. Given mechanical switches often introduce "bounce" you need to handle that too.

However, you may find the PinDetect library really useful. It handles all the debouncing for you and will make callbacks to you functions when a switch is pressed, released or held for a specified period of time. If you connect the switch to 0v and use a pull-up it can even handle the inversed sense for you so reading the pin will appear as 1 when pressed. It does a lot actually and is fully customisable.

There's a simple example to get you going.

Import libraryPinDetect

InterruptIn style DigitalIn debounced with callbacks for pin state change and pin state hold.

17 Mar 2011

Ben Uijtenhaak wrote:

There is a way to connect more than one button to one (analog)input pin. I use 4 push buttons on p15. Works great. Read next document for instructions. http://www.freescale.com/files/microcontrollers/doc/app_note/AN1775.pdf

One thing to be aware of is that the approach described in that Freescale app note is intended for cases where only one switch is active at a time.

It is possible to use a single analog input to detect simultaneous closure of multiple switches, however; you just need a different type of resistor network.

Here is a simple example, for two buttons (like the OP needs):

https://lh3.googleusercontent.com/_uPXih5V64C0/TYJ-akAu8AI/AAAAAAAAAFU/tMrIsD4tZu0/s800/Analog%20Pushbuttons.jpg

I would definitely suggest using the new "de-glitched" AnalogIn library if you choose this method.

18 Mar 2011

Software debouncing is good but you might also want to consider some hardware solutions to make life easier for the software. Options range from a simple low pass filter to a solution that offers protection from over voltage, for example the MAX6818.