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@4:2eceeb929edd, 2018-07-05 (annotated)
- Committer:
- zeneto
- Date:
- Thu Jul 05 00:19:23 2018 +0000
- Revision:
- 4:2eceeb929edd
- Parent:
- 3:81621bb4f009
- Child:
- 5:ffba8ba016a7
VERS?O COM 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 | 4:2eceeb929edd | 4 | //Fazer escalonador com prioridade, para os botões, piscar led em azul com frequencia diferente com as maiores prioridades |
zeneto | 4:2eceeb929edd | 5 | //sensor piscar em vermelho com a prioridade maior |
zeneto | 4:2eceeb929edd | 6 | |
zeneto | 2:82e0ae145867 | 7 | //Interruptions |
zeneto | 2:82e0ae145867 | 8 | InterruptIn btn1(D7); |
zeneto | 2:82e0ae145867 | 9 | InterruptIn btn2(D6); |
zeneto | 2:82e0ae145867 | 10 | InterruptIn btn3(D5); |
zeneto | 2:82e0ae145867 | 11 | InterruptIn btn4(D4); |
zeneto | 2:82e0ae145867 | 12 | |
zeneto | 3:81621bb4f009 | 13 | |
zeneto | 3:81621bb4f009 | 14 | |
zeneto | 2:82e0ae145867 | 15 | //Outs |
zeneto | 2:82e0ae145867 | 16 | DigitalOut buzzer(D2); |
zeneto | 1:e7d2231abccc | 17 | DigitalOut led(LED_BLUE); |
zeneto | 4:2eceeb929edd | 18 | DigitalOut ground(D0); |
zeneto | 3:81621bb4f009 | 19 | |
zeneto | 3:81621bb4f009 | 20 | //Buttons Threads |
zeneto | 3:81621bb4f009 | 21 | Thread threadb1, threadb2, threadb3, threadb4; |
zeneto | 3:81621bb4f009 | 22 | |
zeneto | 4:2eceeb929edd | 23 | //Scheduler Thread |
zeneto | 4:2eceeb929edd | 24 | Thread scdT; |
zeneto | 4:2eceeb929edd | 25 | //Scheduler |
zeneto | 4:2eceeb929edd | 26 | int scd[4]; |
zeneto | 4:2eceeb929edd | 27 | |
zeneto | 4:2eceeb929edd | 28 | //Buttons |
zeneto | 4:2eceeb929edd | 29 | int b1 = 0, b2 = 0, b3 = 0, b4 = 0; |
zeneto | 4:2eceeb929edd | 30 | |
zeneto | 4:2eceeb929edd | 31 | //Scheduler thread |
zeneto | 4:2eceeb929edd | 32 | void scdThread() { |
zeneto | 4:2eceeb929edd | 33 | |
zeneto | 4:2eceeb929edd | 34 | |
zeneto | 4:2eceeb929edd | 35 | |
zeneto | 4:2eceeb929edd | 36 | } |
zeneto | 4:2eceeb929edd | 37 | |
zeneto | 3:81621bb4f009 | 38 | //Button function |
zeneto | 1:e7d2231abccc | 39 | void button_pressed() { |
zeneto | 2:82e0ae145867 | 40 | buzzer = !buzzer; // toggle the LED |
zeneto | 2:82e0ae145867 | 41 | led = !led; |
zeneto | 0:00e9a2a6f73a | 42 | } |
zeneto | 3:81621bb4f009 | 43 | |
zeneto | 3:81621bb4f009 | 44 | //Buttons threads |
zeneto | 3:81621bb4f009 | 45 | void button1_thread() { |
zeneto | 3:81621bb4f009 | 46 | btn1.fall(&button_pressed); // whenever the button falls, execute button_pressed function |
zeneto | 4:2eceeb929edd | 47 | b1 = 1; |
zeneto | 4:2eceeb929edd | 48 | //while(1) {} |
zeneto | 3:81621bb4f009 | 49 | } |
zeneto | 3:81621bb4f009 | 50 | |
zeneto | 3:81621bb4f009 | 51 | void button2_thread() { |
zeneto | 3:81621bb4f009 | 52 | btn2.fall(&button_pressed); // whenever the button falls, execute button_pressed function |
zeneto | 4:2eceeb929edd | 53 | b2 = 1; |
zeneto | 4:2eceeb929edd | 54 | //while(1) {} |
zeneto | 3:81621bb4f009 | 55 | } |
zeneto | 3:81621bb4f009 | 56 | |
zeneto | 3:81621bb4f009 | 57 | void button3_thread() { |
zeneto | 3:81621bb4f009 | 58 | btn3.fall(&button_pressed); // whenever the button falls, execute button_pressed function |
zeneto | 4:2eceeb929edd | 59 | b3 = 1; |
zeneto | 4:2eceeb929edd | 60 | //while(1) {} |
zeneto | 3:81621bb4f009 | 61 | } |
zeneto | 3:81621bb4f009 | 62 | |
zeneto | 3:81621bb4f009 | 63 | void button4_thread() { |
zeneto | 3:81621bb4f009 | 64 | btn4.fall(&button_pressed); // whenever the button falls, execute button_pressed function |
zeneto | 4:2eceeb929edd | 65 | b4 = 1; |
zeneto | 4:2eceeb929edd | 66 | //while(1) {} |
zeneto | 3:81621bb4f009 | 67 | } |
zeneto | 0:00e9a2a6f73a | 68 | |
zeneto | 4:2eceeb929edd | 69 | |
zeneto | 1:e7d2231abccc | 70 | int main(int, char**) { |
zeneto | 4:2eceeb929edd | 71 | ground = 0; |
zeneto | 3:81621bb4f009 | 72 | led = !led; |
zeneto | 3:81621bb4f009 | 73 | threadb1.start(button1_thread); |
zeneto | 3:81621bb4f009 | 74 | threadb2.start(button2_thread); |
zeneto | 3:81621bb4f009 | 75 | threadb3.start(button3_thread); |
zeneto | 3:81621bb4f009 | 76 | threadb4.start(button4_thread); |
zeneto | 4:2eceeb929edd | 77 | scdT.start(scdThread); |
zeneto | 4:2eceeb929edd | 78 | |
zeneto | 1:e7d2231abccc | 79 | |
zeneto | 1:e7d2231abccc | 80 | while (1) {} |
zeneto | 0:00e9a2a6f73a | 81 | } |