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.
InterruptIn style DigitalIn debounced with callbacks for pin state change and pin state hold.
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