SW0, SW1 button int test.

Dependencies:   mbed-src

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 #define BTN0_PIN P6_0
00004 #define BTN1_PIN P6_1
00005 #define BTN0_IRQ IRQ5_IRQn
00006 #define BTN1_IRQ IRQ4_IRQn
00007 
00008 InterruptIn button0(BTN0_PIN);
00009 InterruptIn button1(BTN1_PIN);
00010 DigitalOut rled(LED_RED);
00011 DigitalOut bled(LED_BLUE);
00012 
00013 #define DELAY_CNT 1000000000
00014 
00015 void button0_int_handler() {
00016     rled = 0;
00017     for (int i = 0; i <= DELAY_CNT; i++) ;
00018     rled = 1;
00019 }
00020 
00021 void button1_int_handler() {
00022     bled = 0;
00023     for (int i = 0; i <= DELAY_CNT; i++) ;
00024     bled = 1;
00025 }
00026 
00027 int main() {
00028     rled = 1;
00029     bled = 1;
00030     
00031     GIC_SetPriority(BTN1_IRQ, 10);      // Pri 10 に落とす
00032     button0.fall(&button0_int_handler);
00033     button1.fall(&button1_int_handler);
00034 
00035     while(1) {
00036         wait(1);
00037     }
00038 }