exercise1
Embed:
(wiki syntax)
Show/hide line numbers
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 volatile static time_t begin; 00008 volatile static int pressCount = 0; 00009 00010 void blinkLed1(void){ 00011 led1 = 1; 00012 wait(0.5); 00013 led1 = 0; 00014 } 00015 00016 void rise_handler_thread_context(void) { 00017 printf("Button pressed. count = %d\n", pressCount); 00018 if(pressCount == 1){ 00019 begin = time(NULL); 00020 }else{ 00021 pressCount = 0; 00022 if(time(NULL) - begin < 2){ 00023 printf("Blinking"); 00024 blinkLed1(); 00025 } 00026 } 00027 } 00028 00029 void rise_handler_iterrupt_context(void) { 00030 pressCount += 1; 00031 queue.call(rise_handler_thread_context); 00032 } 00033 00034 int main() { 00035 // Start the event queue 00036 t.start(callback(&queue, &EventQueue::dispatch_forever)); 00037 printf("Starting in context %p\r\n", Thread::gettid()); 00038 // The 'rise' handler will execute in IRQ context 00039 button.rise(rise_handler_iterrupt_context); 00040 }
Generated on Mon Jul 18 2022 11:00:08 by
1.7.2