Toggle led ON pin PA_5 (LED1) when the button on pin PB_4 is released

Dependencies:   Hotboards_buttons mbed

Committer:
Hotboards
Date:
Thu Mar 03 21:42:08 2016 +0000
Revision:
0:8bf973b68f0b
first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Hotboards 0:8bf973b68f0b 1
Hotboards 0:8bf973b68f0b 2 /*
Hotboards 0:8bf973b68f0b 3 * Toggle led ON pin PA_5 (LED1) when the button on pin PB_4 is released
Hotboards 0:8bf973b68f0b 4 */
Hotboards 0:8bf973b68f0b 5
Hotboards 0:8bf973b68f0b 6 #include "mbed.h"
Hotboards 0:8bf973b68f0b 7 #include "Hotboards_buttons.h"
Hotboards 0:8bf973b68f0b 8
Hotboards 0:8bf973b68f0b 9 //Creates a single button object, when the button is pressed it gives you
Hotboards 0:8bf973b68f0b 10 //a LOW(0) value because it works with pull-ups.
Hotboards 0:8bf973b68f0b 11 Hotboards_buttons btn( PB_4 );
Hotboards 0:8bf973b68f0b 12 //If your buttons gives you a HIGH(1) value when is pressed, then we need
Hotboards 0:8bf973b68f0b 13 //to create the button object with and extra parameter:
Hotboards 0:8bf973b68f0b 14 //Hotboards_buttons btn( PB_4 , 1 ); in any case the functions will return
Hotboards 0:8bf973b68f0b 15 //a HIGH(1) value any time the button is pressed
Hotboards 0:8bf973b68f0b 16
Hotboards 0:8bf973b68f0b 17 //To our example we will use the led on the nucleo board
Hotboards 0:8bf973b68f0b 18 DigitalOut nucleoLed( LED1 );
Hotboards 0:8bf973b68f0b 19
Hotboards 0:8bf973b68f0b 20 int main()
Hotboards 0:8bf973b68f0b 21 {
Hotboards 0:8bf973b68f0b 22 while(1)
Hotboards 0:8bf973b68f0b 23 {
Hotboards 0:8bf973b68f0b 24 //The moment when the button is released the function will return a HIGH(1)
Hotboards 0:8bf973b68f0b 25 //value, it doesn`t matter if your button is configured with pull-ups(LOW)
Hotboards 0:8bf973b68f0b 26 //or pull-downs(HIGH)
Hotboards 0:8bf973b68f0b 27 if( btn.isReleased( ) )
Hotboards 0:8bf973b68f0b 28 {
Hotboards 0:8bf973b68f0b 29 //Toggle led on the nucleo board
Hotboards 0:8bf973b68f0b 30 nucleoLed = !nucleoLed;
Hotboards 0:8bf973b68f0b 31 }
Hotboards 0:8bf973b68f0b 32 }
Hotboards 0:8bf973b68f0b 33 }