Eivind Dammen
/
LAB07_Oppgave4
lab 7
Fork of LAB07_Oppgave4_Template by
main.cpp@1:97d80c580b14, 2016-12-10 (annotated)
- Committer:
- eivindd24
- Date:
- Sat Dec 10 10:22:50 2016 +0000
- Revision:
- 1:97d80c580b14
- Parent:
- 0:ce0d1043321f
ok
Who changed what in which revision?
User | Revision | Line number | New 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); |
eivindd24 | 1:97d80c580b14 | 6 | InterruptIn SW7(PB_3); |
eivindd24 | 1:97d80c580b14 | 7 | InterruptIn SW6(PA_10); |
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 | |
eivindd24 | 1:97d80c580b14 | 16 | void SW7Trykk(){ |
eivindd24 | 1:97d80c580b14 | 17 | dutyCycle=dutyCycle+.1f; |
eivindd24 | 1:97d80c580b14 | 18 | } |
eivindd24 | 1:97d80c580b14 | 19 | |
eivindd24 | 1:97d80c580b14 | 20 | void SW6Trykk(){ |
eivindd24 | 1:97d80c580b14 | 21 | |
eivindd24 | 1:97d80c580b14 | 22 | dutyCycle=dutyCycle-.1f; |
eivindd24 | 1:97d80c580b14 | 23 | if(dutyCycle<=0.1) |
eivindd24 | 1:97d80c580b14 | 24 | { |
eivindd24 | 1:97d80c580b14 | 25 | dutyCycle=0.1; |
eivindd24 | 1:97d80c580b14 | 26 | } |
eivindd24 | 1:97d80c580b14 | 27 | |
eivindd24 | 1:97d80c580b14 | 28 | } |
eivindd24 | 1:97d80c580b14 | 29 | |
rlanghbv | 0:ce0d1043321f | 30 | void TurnLightOn() |
rlanghbv | 0:ce0d1043321f | 31 | { led=0; |
rlanghbv | 0:ce0d1043321f | 32 | onTime.attach(&TurnLightOff,(float)periodTime*dutyCycle); |
rlanghbv | 0:ce0d1043321f | 33 | } |
rlanghbv | 0:ce0d1043321f | 34 | |
rlanghbv | 0:ce0d1043321f | 35 | int main() |
rlanghbv | 0:ce0d1043321f | 36 | { |
rlanghbv | 0:ce0d1043321f | 37 | periodTimer.attach(&TurnLightOn,periodTime); |
rlanghbv | 0:ce0d1043321f | 38 | |
rlanghbv | 0:ce0d1043321f | 39 | while(1) { |
eivindd24 | 1:97d80c580b14 | 40 | SW7.fall(&SW7Trykk); |
eivindd24 | 1:97d80c580b14 | 41 | SW6.fall(&SW6Trykk); |
rlanghbv | 0:ce0d1043321f | 42 | wait(1); |
rlanghbv | 0:ce0d1043321f | 43 | } |
rlanghbv | 0:ce0d1043321f | 44 | } |