vjezba 6.2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 Timer timer1; // define timer object
00003 Timer timer2; // define timer object
00004 DigitalOut output1(p21); // digital output
00005 DigitalOut output2(p22); // digital output
00006 void task1(void); // task function prototype
00007 
00008 void task2(void);
00009 //*** main code
00010 int main()
00011 {
00012     timer1.start(); // start timer1 counting
00013     timer2.start(); // start timer2 counting
00014     while(1) {
00015         if (timer1.read_ms()>=200) { // read time
00016             task1(); // call task1 function
00017             timer1.reset(); // reset timer
00018         }
00019         if (timer2.read_ms()>=1000) { // read time
00020             task2(); // call task2 function
00021             timer2.reset(); // reset timer
00022         }
00023     }
00024 }
00025 //*** task functions
00026 void task1(void)
00027 {
00028     output1=!output1; // toggle output1
00029 }
00030 void task2(void)
00031 {
00032     output2=!output2; // toggle output2
00033 }