Kristijan Župančić
/
6-2-dva_tajmera
Dva tajmera 6-2
main.cpp@0:f25029cd4ab4, 2015-12-17 (annotated)
- Committer:
- Kzupancic
- Date:
- Thu Dec 17 15:02:09 2015 +0000
- Revision:
- 0:f25029cd4ab4
Dva tajmera
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kzupancic | 0:f25029cd4ab4 | 1 | #include "mbed.h" |
Kzupancic | 0:f25029cd4ab4 | 2 | |
Kzupancic | 0:f25029cd4ab4 | 3 | |
Kzupancic | 0:f25029cd4ab4 | 4 | Timer timer1; // define timer object |
Kzupancic | 0:f25029cd4ab4 | 5 | Timer timer2; |
Kzupancic | 0:f25029cd4ab4 | 6 | DigitalOut output1(p5); // digital output |
Kzupancic | 0:f25029cd4ab4 | 7 | DigitalOut output2(p5); |
Kzupancic | 0:f25029cd4ab4 | 8 | void task1(void); // task function prototype |
Kzupancic | 0:f25029cd4ab4 | 9 | void task2(void); |
Kzupancic | 0:f25029cd4ab4 | 10 | |
Kzupancic | 0:f25029cd4ab4 | 11 | |
Kzupancic | 0:f25029cd4ab4 | 12 | int main() { |
Kzupancic | 0:f25029cd4ab4 | 13 | timer1.start(); // start timer1 counting |
Kzupancic | 0:f25029cd4ab4 | 14 | timer2.start(); // start timer2 counting |
Kzupancic | 0:f25029cd4ab4 | 15 | while(1) { |
Kzupancic | 0:f25029cd4ab4 | 16 | if (timer1.read_ms()>=200) // read time |
Kzupancic | 0:f25029cd4ab4 | 17 | { |
Kzupancic | 0:f25029cd4ab4 | 18 | task1(); // call task1 function |
Kzupancic | 0:f25029cd4ab4 | 19 | timer1.reset(); // reset timer |
Kzupancic | 0:f25029cd4ab4 | 20 | } |
Kzupancic | 0:f25029cd4ab4 | 21 | if (timer2.read_ms()>=1000) // read time |
Kzupancic | 0:f25029cd4ab4 | 22 | { |
Kzupancic | 0:f25029cd4ab4 | 23 | task2(); // call task2 function |
Kzupancic | 0:f25029cd4ab4 | 24 | timer2.reset(); // reset timer |
Kzupancic | 0:f25029cd4ab4 | 25 | } |
Kzupancic | 0:f25029cd4ab4 | 26 | } |
Kzupancic | 0:f25029cd4ab4 | 27 | } |
Kzupancic | 0:f25029cd4ab4 | 28 | //*** task functions |
Kzupancic | 0:f25029cd4ab4 | 29 | void task1(void){ |
Kzupancic | 0:f25029cd4ab4 | 30 | output1=!output1; // toggle output1 |
Kzupancic | 0:f25029cd4ab4 | 31 | } |
Kzupancic | 0:f25029cd4ab4 | 32 | void task2(void){ |
Kzupancic | 0:f25029cd4ab4 | 33 | output2=!output2; // toggle output2 |
Kzupancic | 0:f25029cd4ab4 | 34 | } |