lab 7

Dependencies:   mbed

Fork of LAB07_Oppgave4_Template by EN-SOC3001

Committer:
rlanghbv
Date:
Wed Oct 14 19:06:20 2015 +0000
Revision:
0:ce0d1043321f
Child:
1:97d80c580b14
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rlanghbv 0:ce0d1043321f 1 #include "mbed.h"
rlanghbv 0:ce0d1043321f 2
rlanghbv 0:ce0d1043321f 3 Timeout onTime;
rlanghbv 0:ce0d1043321f 4 Ticker periodTimer;
rlanghbv 0:ce0d1043321f 5 DigitalOut led(PA_9);
rlanghbv 0:ce0d1043321f 6
rlanghbv 0:ce0d1043321f 7 float periodTime=0.020; // 20ms period time (50Hz)
rlanghbv 0:ce0d1043321f 8 float dutyCycle=.05;
rlanghbv 0:ce0d1043321f 9
rlanghbv 0:ce0d1043321f 10 void TurnLightOff()
rlanghbv 0:ce0d1043321f 11 { led=1;
rlanghbv 0:ce0d1043321f 12 }
rlanghbv 0:ce0d1043321f 13
rlanghbv 0:ce0d1043321f 14 void TurnLightOn()
rlanghbv 0:ce0d1043321f 15 { led=0;
rlanghbv 0:ce0d1043321f 16 onTime.attach(&TurnLightOff,(float)periodTime*dutyCycle);
rlanghbv 0:ce0d1043321f 17 }
rlanghbv 0:ce0d1043321f 18
rlanghbv 0:ce0d1043321f 19 int main()
rlanghbv 0:ce0d1043321f 20 {
rlanghbv 0:ce0d1043321f 21 periodTimer.attach(&TurnLightOn,periodTime);
rlanghbv 0:ce0d1043321f 22
rlanghbv 0:ce0d1043321f 23 while(1) {
rlanghbv 0:ce0d1043321f 24 wait(1);
rlanghbv 0:ce0d1043321f 25 }
rlanghbv 0:ce0d1043321f 26 }