Button with interrupt example.

Dependencies:   mbed

main.cpp

Committer:
bcostm
Date:
22 months ago
Revision:
1:cb693ddbc9b2
Parent:
0:7d38be0bc9c1

File content as of revision 1:cb693ddbc9b2:

#include "mbed.h"

InterruptIn button(USER_BUTTON);

DigitalOut led(LED1);

double delay = 0.5; // 500 ms

void pressed()
{
    delay = 0.1; // 100 ms
}

void released()
{
    delay = 0.5; // 500 ms
}

int main()
{
    // Assign functions to button
    button.fall(&pressed);
    button.rise(&released);

    while (1) {
        led = !led;
        wait(delay);
    }
}