s

Dependencies:   mbed

Fork of LAB07_Oppgave4_Template by EN-SOC3001

Committer:
Voldread
Date:
Thu Oct 15 15:01:49 2015 +0000
Revision:
1:3313c84ab6d7
Parent:
0:ce0d1043321f
S

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rlanghbv 0:ce0d1043321f 1 #include "mbed.h"
rlanghbv 0:ce0d1043321f 2
Voldread 1:3313c84ab6d7 3 Ticker led_ticker;
rlanghbv 0:ce0d1043321f 4 Timeout onTime;
rlanghbv 0:ce0d1043321f 5 Ticker periodTimer;
rlanghbv 0:ce0d1043321f 6 DigitalOut led(PA_9);
Voldread 1:3313c84ab6d7 7 InterruptIn SW6(PA_10), SW7(PB_3);
rlanghbv 0:ce0d1043321f 8
rlanghbv 0:ce0d1043321f 9 float periodTime=0.020; // 20ms period time (50Hz)
rlanghbv 0:ce0d1043321f 10 float dutyCycle=.05;
rlanghbv 0:ce0d1043321f 11
rlanghbv 0:ce0d1043321f 12 void TurnLightOff()
rlanghbv 0:ce0d1043321f 13 { led=1;
rlanghbv 0:ce0d1043321f 14 }
rlanghbv 0:ce0d1043321f 15
rlanghbv 0:ce0d1043321f 16 void TurnLightOn()
rlanghbv 0:ce0d1043321f 17 { led=0;
rlanghbv 0:ce0d1043321f 18 onTime.attach(&TurnLightOff,(float)periodTime*dutyCycle);
rlanghbv 0:ce0d1043321f 19 }
rlanghbv 0:ce0d1043321f 20
Voldread 1:3313c84ab6d7 21 void SW7Trykket()
Voldread 1:3313c84ab6d7 22 { dutyCycle=dutyCycle+.1f;
Voldread 1:3313c84ab6d7 23 //led_ticker.attach(&led, dutyCycle);
Voldread 1:3313c84ab6d7 24 }
Voldread 1:3313c84ab6d7 25 void SW6Trykket()
Voldread 1:3313c84ab6d7 26 { dutyCycle=dutyCycle-.1f;
Voldread 1:3313c84ab6d7 27 //led_ticker.attach(&led, dutyCycle);
Voldread 1:3313c84ab6d7 28 }
Voldread 1:3313c84ab6d7 29
rlanghbv 0:ce0d1043321f 30 int main()
rlanghbv 0:ce0d1043321f 31 {
Voldread 1:3313c84ab6d7 32 if (dutyCycle>0);
rlanghbv 0:ce0d1043321f 33 periodTimer.attach(&TurnLightOn,periodTime);
Voldread 1:3313c84ab6d7 34 SW7.fall(&SW7Trykket);
Voldread 1:3313c84ab6d7 35 SW6.fall(&SW6Trykket);
rlanghbv 0:ce0d1043321f 36
rlanghbv 0:ce0d1043321f 37 while(1) {
rlanghbv 0:ce0d1043321f 38 wait(1);
rlanghbv 0:ce0d1043321f 39 }
rlanghbv 0:ce0d1043321f 40 }