Francesco Arrigo / Mbed 2 deprecated BlinkButton2Sec

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut led1(LED1);
00004 InterruptIn button(USER_BUTTON);
00005 EventQueue queue(32 * EVENTS_EVENT_SIZE);
00006 Thread t;
00007 
00008 volatile time_t first_seconds = 0;
00009 
00010 void fall_handler_thread_context(void) {
00011     printf("rise_handler_thread_context in context %p\r\n", Thread::gettid());
00012     printf("firt_seconds: %d\n", first_seconds);
00013     time_t seconds = time(NULL);
00014     if (first_seconds != 0 && ((seconds - first_seconds) < 2)) {
00015             led1 = !led1;
00016     }
00017     printf("seconds: %d\n", seconds);
00018     first_seconds = seconds; 
00019 }
00020 
00021 void fall_handler_iterrupt_context(void) {
00022     queue.call(fall_handler_thread_context);
00023 }
00024 
00025 
00026 int main() {
00027     // Start the event queue
00028     t.start(callback(&queue, &EventQueue::dispatch_forever));
00029     printf("Starting in context %p\r\n", Thread::gettid());
00030     button.fall(fall_handler_iterrupt_context);
00031 }