Copy 1
Dependencies: mbed
main.cpp@0:bf95f897e13f, 2017-10-24 (annotated)
- Committer:
- motley
- Date:
- Tue Oct 24 13:32:11 2017 +0000
- Revision:
- 0:bf95f897e13f
First
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
motley | 0:bf95f897e13f | 1 | #include "mbed.h" |
motley | 0:bf95f897e13f | 2 | #include "SwitchManager.hpp" |
motley | 0:bf95f897e13f | 3 | |
motley | 0:bf95f897e13f | 4 | #define N 1000000 |
motley | 0:bf95f897e13f | 5 | #define RELEASED 0 |
motley | 0:bf95f897e13f | 6 | #define PRESSED 1 |
motley | 0:bf95f897e13f | 7 | |
motley | 0:bf95f897e13f | 8 | //Function prototypes |
motley | 0:bf95f897e13f | 9 | void isr1(); |
motley | 0:bf95f897e13f | 10 | void isr2(); |
motley | 0:bf95f897e13f | 11 | void isrTick(); |
motley | 0:bf95f897e13f | 12 | |
motley | 0:bf95f897e13f | 13 | //Hardware objects |
motley | 0:bf95f897e13f | 14 | DigitalOut red_led(PE_15); //CountUp is in its critical section |
motley | 0:bf95f897e13f | 15 | DigitalOut yellow_led(PB_10); //CountDown is in its critical section |
motley | 0:bf95f897e13f | 16 | DigitalOut green_led(PB_11); //counter != 0 |
motley | 0:bf95f897e13f | 17 | DigitalOut onboardLED(LED1); |
motley | 0:bf95f897e13f | 18 | |
motley | 0:bf95f897e13f | 19 | InterruptIn sw1(PE_12); |
motley | 0:bf95f897e13f | 20 | InterruptIn sw2(PE_14); |
motley | 0:bf95f897e13f | 21 | Ticker yellowTick; |
motley | 0:bf95f897e13f | 22 | |
motley | 0:bf95f897e13f | 23 | void toggleYellowISR() { |
motley | 0:bf95f897e13f | 24 | yellow_led = !yellow_led; |
motley | 0:bf95f897e13f | 25 | } |
motley | 0:bf95f897e13f | 26 | |
motley | 0:bf95f897e13f | 27 | int main() { |
motley | 0:bf95f897e13f | 28 | |
motley | 0:bf95f897e13f | 29 | //Light up |
motley | 0:bf95f897e13f | 30 | red_led = 1; |
motley | 0:bf95f897e13f | 31 | yellow_led = 1; |
motley | 0:bf95f897e13f | 32 | green_led = 1; |
motley | 0:bf95f897e13f | 33 | onboardLED = 0; |
motley | 0:bf95f897e13f | 34 | |
motley | 0:bf95f897e13f | 35 | //Interrupt controlled red led using sw1 |
motley | 0:bf95f897e13f | 36 | SwitchManager sm1(sw1, red_led); |
motley | 0:bf95f897e13f | 37 | |
motley | 0:bf95f897e13f | 38 | //Interrupt controlled red led using sw2 |
motley | 0:bf95f897e13f | 39 | SwitchManager sm2(sw2, green_led); |
motley | 0:bf95f897e13f | 40 | |
motley | 0:bf95f897e13f | 41 | //Simple ticker |
motley | 0:bf95f897e13f | 42 | yellowTick.attach(&toggleYellowISR, 0.5); |
motley | 0:bf95f897e13f | 43 | |
motley | 0:bf95f897e13f | 44 | //Now loop forever |
motley | 0:bf95f897e13f | 45 | while(1) { |
motley | 0:bf95f897e13f | 46 | sleep(); |
motley | 0:bf95f897e13f | 47 | }; |
motley | 0:bf95f897e13f | 48 | } |
motley | 0:bf95f897e13f | 49 | |
motley | 0:bf95f897e13f | 50 |