Eivind Dammen
/
lab07_oppgave3
oppg3
main.cpp@0:fcf6b30014dc, 2016-12-10 (annotated)
- Committer:
- eivindd24
- Date:
- Sat Dec 10 10:25:56 2016 +0000
- Revision:
- 0:fcf6b30014dc
ok;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eivindd24 | 0:fcf6b30014dc | 1 | #include "mbed.h" |
eivindd24 | 0:fcf6b30014dc | 2 | |
eivindd24 | 0:fcf6b30014dc | 3 | Ticker toggle_led_ticker; |
eivindd24 | 0:fcf6b30014dc | 4 | InterruptIn SW7(PB_3); |
eivindd24 | 0:fcf6b30014dc | 5 | InterruptIn SW6(PA_10); |
eivindd24 | 0:fcf6b30014dc | 6 | float tikerhastighet=0.1; |
eivindd24 | 0:fcf6b30014dc | 7 | DigitalOut led1(PA_9); |
eivindd24 | 0:fcf6b30014dc | 8 | Timeout timeOutIrq; |
eivindd24 | 0:fcf6b30014dc | 9 | |
eivindd24 | 0:fcf6b30014dc | 10 | void toggle_led() |
eivindd24 | 0:fcf6b30014dc | 11 | { |
eivindd24 | 0:fcf6b30014dc | 12 | led1 = !led1; |
eivindd24 | 0:fcf6b30014dc | 13 | } |
eivindd24 | 0:fcf6b30014dc | 14 | |
eivindd24 | 0:fcf6b30014dc | 15 | void enableKnappeTrykk(){ |
eivindd24 | 0:fcf6b30014dc | 16 | SW7.enable_irq(); |
eivindd24 | 0:fcf6b30014dc | 17 | SW6.enable_irq(); |
eivindd24 | 0:fcf6b30014dc | 18 | } |
eivindd24 | 0:fcf6b30014dc | 19 | |
eivindd24 | 0:fcf6b30014dc | 20 | |
eivindd24 | 0:fcf6b30014dc | 21 | void sw7Trykket() |
eivindd24 | 0:fcf6b30014dc | 22 | { |
eivindd24 | 0:fcf6b30014dc | 23 | SW7.disable_irq(); |
eivindd24 | 0:fcf6b30014dc | 24 | timeOutIrq.attach(&enableKnappeTrykk,.5); |
eivindd24 | 0:fcf6b30014dc | 25 | tikerhastighet=tikerhastighet-.01f; |
eivindd24 | 0:fcf6b30014dc | 26 | toggle_led_ticker.attach(&toggle_led, tikerhastighet); |
eivindd24 | 0:fcf6b30014dc | 27 | } |
eivindd24 | 0:fcf6b30014dc | 28 | |
eivindd24 | 0:fcf6b30014dc | 29 | void sw6Trykket() |
eivindd24 | 0:fcf6b30014dc | 30 | { |
eivindd24 | 0:fcf6b30014dc | 31 | SW6.disable_irq(); |
eivindd24 | 0:fcf6b30014dc | 32 | timeOutIrq.attach(&enableKnappeTrykk,.5); |
eivindd24 | 0:fcf6b30014dc | 33 | tikerhastighet=tikerhastighet+.01f; |
eivindd24 | 0:fcf6b30014dc | 34 | toggle_led_ticker.attach(&toggle_led, tikerhastighet); |
eivindd24 | 0:fcf6b30014dc | 35 | |
eivindd24 | 0:fcf6b30014dc | 36 | } |
eivindd24 | 0:fcf6b30014dc | 37 | |
eivindd24 | 0:fcf6b30014dc | 38 | int main() { |
eivindd24 | 0:fcf6b30014dc | 39 | // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms) |
eivindd24 | 0:fcf6b30014dc | 40 | toggle_led_ticker.attach(&toggle_led, 0.1); |
eivindd24 | 0:fcf6b30014dc | 41 | while (true) |
eivindd24 | 0:fcf6b30014dc | 42 | { |
eivindd24 | 0:fcf6b30014dc | 43 | SW6.fall(&sw6Trykket); |
eivindd24 | 0:fcf6b30014dc | 44 | SW7.fall(&sw7Trykket); |
eivindd24 | 0:fcf6b30014dc | 45 | |
eivindd24 | 0:fcf6b30014dc | 46 | } |
eivindd24 | 0:fcf6b30014dc | 47 | } |