Roman Valencia / Mbed 2 deprecated button_status

Dependencies:   Hotboards_buttons mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 /*
00003  * The simplest program, read a single button on pin PB_4
00004  */
00005  
00006 #include "mbed.h"
00007 #include "Hotboards_buttons.h"
00008 
00009 //Creates a single button object, when the button is pressed it gives you
00010 //a LOW(0) value because it works with pull-ups.
00011 Hotboards_buttons btn( PB_4 );
00012 //If your buttons gives you a HIGH(1) value when is pressed, then we need
00013 //to create the button object with and extra parameter:
00014 //Hotboards_buttons btn( PB_4 , 1 ); in any case the functions will return
00015 //a HIGH(1) value any time the button is pressed
00016 
00017 //To our example we will use the led on the nucleo board
00018 DigitalOut nucleoLed( LED1 );
00019 
00020 int main()
00021 {
00022     while(1)
00023     {
00024         //The moment when the button is pressed the function will return a HIGH(1)
00025         //value, it doesn`t matter if your button is configured with pull-ups(LOW)
00026         //or pull-downs(HIGH)
00027         if( btn.status() )
00028         {
00029             //Button is pressed, led on the nucleo board is ON
00030             nucleoLed = 1;
00031         }
00032         else
00033         {
00034             //Button is not pressed, led on the nucleo board is OFF
00035             nucleoLed = 0;
00036         }
00037         //Just to poll not so often
00038         wait_ms( 50 );
00039     }
00040 }