
asking if the button is released
Dependencies: Hotboards_buttons mbed
main.cpp@0:6346669b34d4, 2016-02-29 (annotated)
- Committer:
- RomanValenciaP
- Date:
- Mon Feb 29 20:56:59 2016 +0000
- Revision:
- 0:6346669b34d4
first release - recquires approval
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RomanValenciaP | 0:6346669b34d4 | 1 | |
RomanValenciaP | 0:6346669b34d4 | 2 | /* |
RomanValenciaP | 0:6346669b34d4 | 3 | * Toggle led ON pin PA_5 (LED1) when the button on pin PB_4 is released |
RomanValenciaP | 0:6346669b34d4 | 4 | */ |
RomanValenciaP | 0:6346669b34d4 | 5 | |
RomanValenciaP | 0:6346669b34d4 | 6 | #include "mbed.h" |
RomanValenciaP | 0:6346669b34d4 | 7 | #include "Hotboards_buttons.h" |
RomanValenciaP | 0:6346669b34d4 | 8 | |
RomanValenciaP | 0:6346669b34d4 | 9 | //Creates a single button object, when the button is pressed it gives you |
RomanValenciaP | 0:6346669b34d4 | 10 | //a LOW(0) value because it works with pull-ups. |
RomanValenciaP | 0:6346669b34d4 | 11 | Hotboards_buttons btn( PB_4 ); |
RomanValenciaP | 0:6346669b34d4 | 12 | //If your buttons gives you a HIGH(1) value when is pressed, then we need |
RomanValenciaP | 0:6346669b34d4 | 13 | //to create the button object with and extra parameter: |
RomanValenciaP | 0:6346669b34d4 | 14 | //Hotboards_buttons btn( PB_4 , 1 ); in any case the functions will return |
RomanValenciaP | 0:6346669b34d4 | 15 | //a HIGH(1) value any time the button is pressed |
RomanValenciaP | 0:6346669b34d4 | 16 | |
RomanValenciaP | 0:6346669b34d4 | 17 | //To our example we will use the led on the nucleo board |
RomanValenciaP | 0:6346669b34d4 | 18 | DigitalOut nucleoLed( LED1 ); |
RomanValenciaP | 0:6346669b34d4 | 19 | |
RomanValenciaP | 0:6346669b34d4 | 20 | int main() |
RomanValenciaP | 0:6346669b34d4 | 21 | { |
RomanValenciaP | 0:6346669b34d4 | 22 | while(1) |
RomanValenciaP | 0:6346669b34d4 | 23 | { |
RomanValenciaP | 0:6346669b34d4 | 24 | //The moment when the button is released the function will return a HIGH(1) |
RomanValenciaP | 0:6346669b34d4 | 25 | //value, it doesn`t matter if your button is configured with pull-ups(LOW) |
RomanValenciaP | 0:6346669b34d4 | 26 | //or pull-downs(HIGH) |
RomanValenciaP | 0:6346669b34d4 | 27 | if( btn.isReleased( ) ) |
RomanValenciaP | 0:6346669b34d4 | 28 | { |
RomanValenciaP | 0:6346669b34d4 | 29 | //Toggle led on the nucleo board |
RomanValenciaP | 0:6346669b34d4 | 30 | nucleoLed = !nucleoLed; |
RomanValenciaP | 0:6346669b34d4 | 31 | } |
RomanValenciaP | 0:6346669b34d4 | 32 | } |
RomanValenciaP | 0:6346669b34d4 | 33 | } |