Ken Segler
/
ezLCD4_mbed
Not Complete
Fork of Nucleo_rtos by
main.cpp@73:d3b295249699, 2015-04-16 (annotated)
- Committer:
- bcostm
- Date:
- Thu Apr 16 08:10:26 2015 +0000
- Revision:
- 73:d3b295249699
- Child:
- 77:cd59ac40b3be
Add main.cpp file
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 73:d3b295249699 | 1 | #include "mbed.h" |
bcostm | 73:d3b295249699 | 2 | #include "rtos.h" |
bcostm | 73:d3b295249699 | 3 | |
bcostm | 73:d3b295249699 | 4 | DigitalOut led(LED1); |
bcostm | 73:d3b295249699 | 5 | |
bcostm | 73:d3b295249699 | 6 | InterruptIn button(USER_BUTTON); |
bcostm | 73:d3b295249699 | 7 | |
bcostm | 73:d3b295249699 | 8 | uint32_t button_pressed; |
bcostm | 73:d3b295249699 | 9 | Thread *thread2; |
bcostm | 73:d3b295249699 | 10 | |
bcostm | 73:d3b295249699 | 11 | void button_press(void) |
bcostm | 73:d3b295249699 | 12 | { |
bcostm | 73:d3b295249699 | 13 | thread2->signal_set(0x1); |
bcostm | 73:d3b295249699 | 14 | } |
bcostm | 73:d3b295249699 | 15 | |
bcostm | 73:d3b295249699 | 16 | void led_thread(void const *argument) |
bcostm | 73:d3b295249699 | 17 | { |
bcostm | 73:d3b295249699 | 18 | while (true) { |
bcostm | 73:d3b295249699 | 19 | led = !led; |
bcostm | 73:d3b295249699 | 20 | Thread::wait(1000); |
bcostm | 73:d3b295249699 | 21 | } |
bcostm | 73:d3b295249699 | 22 | } |
bcostm | 73:d3b295249699 | 23 | |
bcostm | 73:d3b295249699 | 24 | void button_thread(void const *argument) |
bcostm | 73:d3b295249699 | 25 | { |
bcostm | 73:d3b295249699 | 26 | while (true) { |
bcostm | 73:d3b295249699 | 27 | Thread::signal_wait(0x1); |
bcostm | 73:d3b295249699 | 28 | button_pressed++; |
bcostm | 73:d3b295249699 | 29 | } |
bcostm | 73:d3b295249699 | 30 | } |
bcostm | 73:d3b295249699 | 31 | |
bcostm | 73:d3b295249699 | 32 | int main() |
bcostm | 73:d3b295249699 | 33 | { |
bcostm | 73:d3b295249699 | 34 | Thread thread(led_thread); |
bcostm | 73:d3b295249699 | 35 | thread2 = new Thread(button_thread); |
bcostm | 73:d3b295249699 | 36 | |
bcostm | 73:d3b295249699 | 37 | printf("mbed RTOS example\n"); |
bcostm | 73:d3b295249699 | 38 | |
bcostm | 73:d3b295249699 | 39 | button_pressed = 0; |
bcostm | 73:d3b295249699 | 40 | button.fall(&button_press); |
bcostm | 73:d3b295249699 | 41 | |
bcostm | 73:d3b295249699 | 42 | while (true) { |
bcostm | 73:d3b295249699 | 43 | Thread::wait(6000); |
bcostm | 73:d3b295249699 | 44 | printf("During the last 6 seconds, the Button was pressed %d times\n", button_pressed); |
bcostm | 73:d3b295249699 | 45 | fflush(stdout); |
bcostm | 73:d3b295249699 | 46 | button_pressed = 0; |
bcostm | 73:d3b295249699 | 47 | } |
bcostm | 73:d3b295249699 | 48 | } |