ferney alberto beltran molina
/
TimerE3RTOS
EJEMPLO3
main.cpp@0:a550aef65fac, 2017-10-28 (annotated)
- Committer:
- fabeltranm
- Date:
- Sat Oct 28 01:54:47 2017 +0000
- Revision:
- 0:a550aef65fac
- Child:
- 1:0f682b1c98ec
RTQ
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabeltranm | 0:a550aef65fac | 1 | #include "mbed.h" |
fabeltranm | 0:a550aef65fac | 2 | |
fabeltranm | 0:a550aef65fac | 3 | |
fabeltranm | 0:a550aef65fac | 4 | Ticker tk1; |
fabeltranm | 0:a550aef65fac | 5 | Ticker tk2; |
fabeltranm | 0:a550aef65fac | 6 | DigitalOut output1(LED1); // digital output |
fabeltranm | 0:a550aef65fac | 7 | Serial serial(USBTX, USBRX); |
fabeltranm | 0:a550aef65fac | 8 | |
fabeltranm | 0:a550aef65fac | 9 | |
fabeltranm | 0:a550aef65fac | 10 | void task1(void); // task function prototype |
fabeltranm | 0:a550aef65fac | 11 | void task2(void); // task function prototype |
fabeltranm | 0:a550aef65fac | 12 | |
fabeltranm | 0:a550aef65fac | 13 | |
fabeltranm | 0:a550aef65fac | 14 | |
fabeltranm | 0:a550aef65fac | 15 | //*** main code |
fabeltranm | 0:a550aef65fac | 16 | |
fabeltranm | 0:a550aef65fac | 17 | void main() { |
fabeltranm | 0:a550aef65fac | 18 | output1=0; |
fabeltranm | 0:a550aef65fac | 19 | tk1.attach(&task1, 0.8); |
fabeltranm | 0:a550aef65fac | 20 | tk2.attach(&task2, 0.6); |
fabeltranm | 0:a550aef65fac | 21 | while(1) { |
fabeltranm | 0:a550aef65fac | 22 | wait_ms(2000); |
fabeltranm | 0:a550aef65fac | 23 | output1=!output1; // toggle output |
fabeltranm | 0:a550aef65fac | 24 | } |
fabeltranm | 0:a550aef65fac | 25 | } |
fabeltranm | 0:a550aef65fac | 26 | void task1(void){ // task function |
fabeltranm | 0:a550aef65fac | 27 | |
fabeltranm | 0:a550aef65fac | 28 | serial.printf("hola soy task1\n"); |
fabeltranm | 0:a550aef65fac | 29 | wait_ms(300); |
fabeltranm | 0:a550aef65fac | 30 | |
fabeltranm | 0:a550aef65fac | 31 | |
fabeltranm | 0:a550aef65fac | 32 | } |
fabeltranm | 0:a550aef65fac | 33 | |
fabeltranm | 0:a550aef65fac | 34 | void task2(void){ // task function |
fabeltranm | 0:a550aef65fac | 35 | |
fabeltranm | 0:a550aef65fac | 36 | serial.printf("hola soy task2\n"); |
fabeltranm | 0:a550aef65fac | 37 | wait_ms(300); |
fabeltranm | 0:a550aef65fac | 38 | |
fabeltranm | 0:a550aef65fac | 39 | } |