Read a digital value using the button

Dependencies:   mbed

main.cpp

Committer:
jose_23991
Date:
2014-09-08
Revision:
0:56ee1a2414d7

File content as of revision 0:56ee1a2414d7:

#include "mbed.h"
  
int main()
{
    DigitalIn button(USER_BUTTON, PullUp); // Create the button object and setup internall pull-up resistor
    DigitalOut led(LED1, 0);               // Create the LED object and setup OFF

    while(1)
    {
        if(button == 0)                    // Button is pressed
        {
            wait_ms(500);                  // Wait 500ms to debounce
            led = !led;                    // Toggle the LED state
        }
    }
}