Basic example showing how to read a button with interrupt.

Dependencies:   mbed

main.cpp

Committer:
arostm
Date:
2017-06-07
Revision:
1:a6ed173ce041
Parent:
0:2faf62d5a08c

File content as of revision 1:a6ed173ce041:

#include "mbed.h"

DigitalOut green_led(LED1);
DigitalOut red_led(LED2);

InterruptIn user_button(USER_BUTTON);

void button_pressed()
{
  green_led = 1;
}

void button_released()
{
  green_led = 0;
}

int main() {
    
    user_button.rise(&button_pressed);
    user_button.fall(&button_released);
    
    while(1) {
        red_led = !red_led;
        wait(0.2);
    }

}