Matija Berecek
/
VTMatija_Berecek
Vjezba 6.2 (2xledtimer)
main.cpp@0:9fce9f0f1011, 2016-11-10 (annotated)
- Committer:
- Beromunja
- Date:
- Thu Nov 10 17:43:00 2016 +0000
- Revision:
- 0:9fce9f0f1011
VT2 Matija_Berecek
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Beromunja | 0:9fce9f0f1011 | 1 | #include "mbed.h" |
Beromunja | 0:9fce9f0f1011 | 2 | Timer timer1 ; // define timer object |
Beromunja | 0:9fce9f0f1011 | 3 | Timer timer2; |
Beromunja | 0:9fce9f0f1011 | 4 | DigitalOut output1(p5); // digital output |
Beromunja | 0:9fce9f0f1011 | 5 | DigitalOut output2(p6); |
Beromunja | 0:9fce9f0f1011 | 6 | void task1(void); // task function prototype |
Beromunja | 0:9fce9f0f1011 | 7 | void task2(void); |
Beromunja | 0:9fce9f0f1011 | 8 | //*** main code |
Beromunja | 0:9fce9f0f1011 | 9 | int main() { |
Beromunja | 0:9fce9f0f1011 | 10 | timer1.start(); // start timer1 counting |
Beromunja | 0:9fce9f0f1011 | 11 | timer2.start(); // start timer2 counting |
Beromunja | 0:9fce9f0f1011 | 12 | while(1) { |
Beromunja | 0:9fce9f0f1011 | 13 | if (timer1.read_ms()>=200) // read time |
Beromunja | 0:9fce9f0f1011 | 14 | { |
Beromunja | 0:9fce9f0f1011 | 15 | task1(); // call task1 function |
Beromunja | 0:9fce9f0f1011 | 16 | timer1.reset(); // reset timer |
Beromunja | 0:9fce9f0f1011 | 17 | } |
Beromunja | 0:9fce9f0f1011 | 18 | if (timer2.read_ms()>=1000) // read time |
Beromunja | 0:9fce9f0f1011 | 19 | { |
Beromunja | 0:9fce9f0f1011 | 20 | task2(); // call task2 function |
Beromunja | 0:9fce9f0f1011 | 21 | timer2.reset(); // reset timer |
Beromunja | 0:9fce9f0f1011 | 22 | } |
Beromunja | 0:9fce9f0f1011 | 23 | } |
Beromunja | 0:9fce9f0f1011 | 24 | } |
Beromunja | 0:9fce9f0f1011 | 25 | //*** task functions |
Beromunja | 0:9fce9f0f1011 | 26 | void task1(void){ |
Beromunja | 0:9fce9f0f1011 | 27 | output1=!output1; // toggle output1 |
Beromunja | 0:9fce9f0f1011 | 28 | } |
Beromunja | 0:9fce9f0f1011 | 29 | void task2(void){ |
Beromunja | 0:9fce9f0f1011 | 30 | output2=!output2; // toggle output2 |
Beromunja | 0:9fce9f0f1011 | 31 | } |