Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@3:81621bb4f009, 2018-07-04 (annotated)
- Committer:
- zeneto
- Date:
- Wed Jul 04 00:01:47 2018 +0000
- Revision:
- 3:81621bb4f009
- Parent:
- 2:82e0ae145867
- Child:
- 4:2eceeb929edd
vers?o funcionando com threads nos bot?es
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
zeneto | 0:00e9a2a6f73a | 1 | #include "mbed.h" |
zeneto | 3:81621bb4f009 | 2 | #include "rtos.h" |
zeneto | 1:e7d2231abccc | 3 | |
zeneto | 2:82e0ae145867 | 4 | //Interruptions |
zeneto | 2:82e0ae145867 | 5 | InterruptIn btn1(D7); |
zeneto | 2:82e0ae145867 | 6 | InterruptIn btn2(D6); |
zeneto | 2:82e0ae145867 | 7 | InterruptIn btn3(D5); |
zeneto | 2:82e0ae145867 | 8 | InterruptIn btn4(D4); |
zeneto | 2:82e0ae145867 | 9 | |
zeneto | 3:81621bb4f009 | 10 | |
zeneto | 3:81621bb4f009 | 11 | |
zeneto | 2:82e0ae145867 | 12 | //Outs |
zeneto | 2:82e0ae145867 | 13 | DigitalOut buzzer(D2); |
zeneto | 1:e7d2231abccc | 14 | DigitalOut led(LED_BLUE); |
zeneto | 3:81621bb4f009 | 15 | |
zeneto | 3:81621bb4f009 | 16 | //Buttons Threads |
zeneto | 3:81621bb4f009 | 17 | Thread threadb1, threadb2, threadb3, threadb4; |
zeneto | 3:81621bb4f009 | 18 | |
zeneto | 3:81621bb4f009 | 19 | //Button function |
zeneto | 1:e7d2231abccc | 20 | void button_pressed() { |
zeneto | 2:82e0ae145867 | 21 | buzzer = !buzzer; // toggle the LED |
zeneto | 2:82e0ae145867 | 22 | led = !led; |
zeneto | 0:00e9a2a6f73a | 23 | } |
zeneto | 3:81621bb4f009 | 24 | |
zeneto | 3:81621bb4f009 | 25 | //Buttons threads |
zeneto | 3:81621bb4f009 | 26 | void button1_thread() { |
zeneto | 3:81621bb4f009 | 27 | btn1.fall(&button_pressed); // whenever the button falls, execute button_pressed function |
zeneto | 3:81621bb4f009 | 28 | while(1) {} |
zeneto | 3:81621bb4f009 | 29 | } |
zeneto | 3:81621bb4f009 | 30 | |
zeneto | 3:81621bb4f009 | 31 | void button2_thread() { |
zeneto | 3:81621bb4f009 | 32 | btn2.fall(&button_pressed); // whenever the button falls, execute button_pressed function |
zeneto | 3:81621bb4f009 | 33 | while(1) {} |
zeneto | 3:81621bb4f009 | 34 | } |
zeneto | 3:81621bb4f009 | 35 | |
zeneto | 3:81621bb4f009 | 36 | void button3_thread() { |
zeneto | 3:81621bb4f009 | 37 | btn3.fall(&button_pressed); // whenever the button falls, execute button_pressed function |
zeneto | 3:81621bb4f009 | 38 | while(1) {} |
zeneto | 3:81621bb4f009 | 39 | } |
zeneto | 3:81621bb4f009 | 40 | |
zeneto | 3:81621bb4f009 | 41 | void button4_thread() { |
zeneto | 3:81621bb4f009 | 42 | btn4.fall(&button_pressed); // whenever the button falls, execute button_pressed function |
zeneto | 3:81621bb4f009 | 43 | while(1) {} |
zeneto | 3:81621bb4f009 | 44 | } |
zeneto | 0:00e9a2a6f73a | 45 | |
zeneto | 1:e7d2231abccc | 46 | int main(int, char**) { |
zeneto | 3:81621bb4f009 | 47 | led = !led; |
zeneto | 3:81621bb4f009 | 48 | threadb1.start(button1_thread); |
zeneto | 3:81621bb4f009 | 49 | threadb2.start(button2_thread); |
zeneto | 3:81621bb4f009 | 50 | threadb3.start(button3_thread); |
zeneto | 3:81621bb4f009 | 51 | threadb4.start(button4_thread); |
zeneto | 1:e7d2231abccc | 52 | |
zeneto | 1:e7d2231abccc | 53 | while (1) {} |
zeneto | 0:00e9a2a6f73a | 54 | } |