NuMaker GPIO Interrupt with Debounce Setting

main.cpp

Committer:
SHLIU1@OANBE02333.nuvoton.com
Date:
2021-02-25
Revision:
18:a53eb3c1d7b7
Parent:
17:707b60147ca6
Child:
19:6e52d72cc78b

File content as of revision 18:a53eb3c1d7b7:

// GPIO interrupt to set led on/off
#include "mbed.h"

#if defined(TARGET_NUMAKER_PFM_NUC472)
InterruptIn button(SW1);
DigitalOut led(LED1);
#elif defined(TARGET_NUMAKER_PFM_M453)
InterruptIn button(SW2);
DigitalOut led(LED1);
#elif defined(TARGET_NUMAKER_PFM_M487)
InterruptIn button(SW2);
DigitalOut led(LED1);
#elif defined(TARGET_NUMAKER_IOT_M487)
InterruptIn button(SW2);
DigitalOut led(LED1);
#elif defined(TARGET_NUMAKER_PFM_NANO130)
InterruptIn button(SW2);
DigitalOut led(LED1);
#elif defined(TARGET_NUMAKER_PFM_M2351)
InterruptIn button(SW2);
DigitalOut led(LED1);
#elif defined(TARGET_NUMAKER_IOT_M263A)
InterruptIn button(PG_4); // Button1 (SW10)
DigitalOut led(LED1);
#endif

void flip() {
    led = !led;
}

int main() {
#ifdef MBED_MAJOR_VERSION
    printf("Mbed OS version %d.%d.%d\r\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
#endif
    button.rise(&flip);
}