Timer multipli

Dependencies:   mbed

Committer:
MDevolution
Date:
Mon Oct 31 10:35:24 2016 +0000
Revision:
0:12ce453afc0a
Esercitazione5_4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MDevolution 0:12ce453afc0a 1 #include "mbed.h"
MDevolution 0:12ce453afc0a 2 Timer timer_fast; // define Timer with name "timer_fast"
MDevolution 0:12ce453afc0a 3 Timer timer_slow; // define Timer with name "timer_slow"
MDevolution 0:12ce453afc0a 4 DigitalOut out1(D7);
MDevolution 0:12ce453afc0a 5 DigitalOut out2(D8);
MDevolution 0:12ce453afc0a 6
MDevolution 0:12ce453afc0a 7 void task_fast(void); //function prototypes
MDevolution 0:12ce453afc0a 8 void task_slow(void);
MDevolution 0:12ce453afc0a 9
MDevolution 0:12ce453afc0a 10 int main() {
MDevolution 0:12ce453afc0a 11 timer_fast.start(); //start the Timers
MDevolution 0:12ce453afc0a 12 timer_slow.start();
MDevolution 0:12ce453afc0a 13
MDevolution 0:12ce453afc0a 14 while(1){
MDevolution 0:12ce453afc0a 15 if(timer_fast.read_ms()>1){
MDevolution 0:12ce453afc0a 16 task_fast();
MDevolution 0:12ce453afc0a 17 timer_fast.reset();
MDevolution 0:12ce453afc0a 18 }
MDevolution 0:12ce453afc0a 19 if(timer_slow.read_ms()>10){
MDevolution 0:12ce453afc0a 20 task_slow();
MDevolution 0:12ce453afc0a 21 timer_slow.reset();
MDevolution 0:12ce453afc0a 22 }
MDevolution 0:12ce453afc0a 23 }
MDevolution 0:12ce453afc0a 24 }
MDevolution 0:12ce453afc0a 25
MDevolution 0:12ce453afc0a 26 void task_fast(void){
MDevolution 0:12ce453afc0a 27 out1=!out1;
MDevolution 0:12ce453afc0a 28 }
MDevolution 0:12ce453afc0a 29
MDevolution 0:12ce453afc0a 30 void task_slow(void){
MDevolution 0:12ce453afc0a 31 out2=!out2;
MDevolution 0:12ce453afc0a 32 }