Francesco Arrigo
/
BlinkButton2Sec
BlinkButton2Sec assignment
main.cpp@0:30bd725c73f0, 2018-11-29 (annotated)
- Committer:
- framtk
- Date:
- Thu Nov 29 19:31:29 2018 +0000
- Revision:
- 0:30bd725c73f0
done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
framtk | 0:30bd725c73f0 | 1 | #include "mbed.h" |
framtk | 0:30bd725c73f0 | 2 | |
framtk | 0:30bd725c73f0 | 3 | DigitalOut led1(LED1); |
framtk | 0:30bd725c73f0 | 4 | InterruptIn button(USER_BUTTON); |
framtk | 0:30bd725c73f0 | 5 | EventQueue queue(32 * EVENTS_EVENT_SIZE); |
framtk | 0:30bd725c73f0 | 6 | Thread t; |
framtk | 0:30bd725c73f0 | 7 | |
framtk | 0:30bd725c73f0 | 8 | volatile time_t first_seconds = 0; |
framtk | 0:30bd725c73f0 | 9 | |
framtk | 0:30bd725c73f0 | 10 | void fall_handler_thread_context(void) { |
framtk | 0:30bd725c73f0 | 11 | printf("rise_handler_thread_context in context %p\r\n", Thread::gettid()); |
framtk | 0:30bd725c73f0 | 12 | printf("firt_seconds: %d\n", first_seconds); |
framtk | 0:30bd725c73f0 | 13 | time_t seconds = time(NULL); |
framtk | 0:30bd725c73f0 | 14 | if (first_seconds != 0 && ((seconds - first_seconds) < 2)) { |
framtk | 0:30bd725c73f0 | 15 | led1 = !led1; |
framtk | 0:30bd725c73f0 | 16 | } |
framtk | 0:30bd725c73f0 | 17 | printf("seconds: %d\n", seconds); |
framtk | 0:30bd725c73f0 | 18 | first_seconds = seconds; |
framtk | 0:30bd725c73f0 | 19 | } |
framtk | 0:30bd725c73f0 | 20 | |
framtk | 0:30bd725c73f0 | 21 | void fall_handler_iterrupt_context(void) { |
framtk | 0:30bd725c73f0 | 22 | queue.call(fall_handler_thread_context); |
framtk | 0:30bd725c73f0 | 23 | } |
framtk | 0:30bd725c73f0 | 24 | |
framtk | 0:30bd725c73f0 | 25 | |
framtk | 0:30bd725c73f0 | 26 | int main() { |
framtk | 0:30bd725c73f0 | 27 | // Start the event queue |
framtk | 0:30bd725c73f0 | 28 | t.start(callback(&queue, &EventQueue::dispatch_forever)); |
framtk | 0:30bd725c73f0 | 29 | printf("Starting in context %p\r\n", Thread::gettid()); |
framtk | 0:30bd725c73f0 | 30 | button.fall(fall_handler_iterrupt_context); |
framtk | 0:30bd725c73f0 | 31 | } |