NuMaker GPIO Interrupt with Debounce Setting

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 // GPIO interrupt to set led on/off
00002 #include "mbed.h"
00003 
00004 #if defined(TARGET_NUMAKER_PFM_NUC472)
00005 InterruptIn button(SW1);
00006 DigitalOut led(LED1);
00007 #elif defined(TARGET_NUMAKER_PFM_M453)
00008 InterruptIn button(SW2);
00009 DigitalOut led(LED1);
00010 #elif defined(TARGET_NUMAKER_PFM_M487)
00011 InterruptIn button(SW2);
00012 DigitalOut led(LED1);
00013 #elif defined(TARGET_NUMAKER_IOT_M487)
00014 InterruptIn button(SW2);
00015 DigitalOut led(LED1);
00016 #elif defined(TARGET_NUMAKER_PFM_NANO130)
00017 InterruptIn button(SW2);
00018 DigitalOut led(LED1);
00019 #elif defined(TARGET_NUMAKER_PFM_M2351)
00020 InterruptIn button(SW2);
00021 DigitalOut led(LED1);
00022 #elif defined(TARGET_NUMAKER_IOT_M263A)
00023 InterruptIn button(PG_4); // Button1 (SW10)
00024 DigitalOut led(LED1);
00025 #elif defined(TARGET_NUMAKER_IOT_M467)
00026 InterruptIn button(BUTTON1);
00027 DigitalOut led(LED1);
00028 #endif
00029 
00030 void flip() {
00031     led = !led;
00032 }
00033 
00034 int main() {
00035 #ifdef MBED_MAJOR_VERSION
00036     printf("Mbed OS version %d.%d.%d\r\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
00037 #endif
00038     button.rise(&flip);
00039 }