LEDs/Button example.
Dependencies: mbed
main.cpp@1:d343cf676574, 2017-05-17 (annotated)
- Committer:
- arostm
- Date:
- Wed May 17 09:17:45 2017 +0200
- Revision:
- 1:d343cf676574
- Parent:
- 0:2bd4c0051d9a
- Child:
- 2:603a8ac68090
modify main.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:2bd4c0051d9a | 1 | #include "mbed.h" |
bcostm | 0:2bd4c0051d9a | 2 | |
arostm | 1:d343cf676574 | 3 | DigitalOut myled1(LED1); |
arostm | 1:d343cf676574 | 4 | DigitalOut myled2(LED2); |
arostm | 1:d343cf676574 | 5 | DigitalOut myled3(LED3); |
arostm | 1:d343cf676574 | 6 | DigitalOut myled4(LED4); |
arostm | 1:d343cf676574 | 7 | |
arostm | 1:d343cf676574 | 8 | InterruptIn mybutton(USER_BUTTON); |
arostm | 1:d343cf676574 | 9 | |
arostm | 1:d343cf676574 | 10 | double tempo = 0.2; //time to wait |
arostm | 1:d343cf676574 | 11 | |
arostm | 1:d343cf676574 | 12 | void changetempo() { |
arostm | 1:d343cf676574 | 13 | if(tempo == 0.2) // If leds have low frequency |
arostm | 1:d343cf676574 | 14 | tempo = 0.1; // Set the fast frequency |
arostm | 1:d343cf676574 | 15 | else // If les have fast frequency |
arostm | 1:d343cf676574 | 16 | tempo = 0.2; // Set the low frequency |
bcostm | 0:2bd4c0051d9a | 17 | } |
arostm | 1:d343cf676574 | 18 | |
arostm | 1:d343cf676574 | 19 | int main() { |
arostm | 1:d343cf676574 | 20 | myled1 = 0; //LED1 is OFF |
arostm | 1:d343cf676574 | 21 | myled2 = 0; //LED2 is OFF |
arostm | 1:d343cf676574 | 22 | myled3 = 0; //LED3 is OFF |
arostm | 1:d343cf676574 | 23 | myled4 = 0; //LED4 is OFF |
arostm | 1:d343cf676574 | 24 | |
arostm | 1:d343cf676574 | 25 | mybutton.fall(&changetempo); //Interrupt to change tempo |
arostm | 1:d343cf676574 | 26 | |
arostm | 1:d343cf676574 | 27 | while(1) { |
arostm | 1:d343cf676574 | 28 | myled2 = 1; // LED2 is ON |
arostm | 1:d343cf676574 | 29 | wait(tempo); // wait tempo |
arostm | 1:d343cf676574 | 30 | myled2 = 0; // LED2 is OFF |
arostm | 1:d343cf676574 | 31 | myled1 = 1; // LED1 is ON |
arostm | 1:d343cf676574 | 32 | wait(tempo); // wait tempo |
arostm | 1:d343cf676574 | 33 | myled1 = 0; // LED1 is OFF |
arostm | 1:d343cf676574 | 34 | myled3 = 1; // LED3 is ON |
arostm | 1:d343cf676574 | 35 | wait(tempo); // wait tempo |
arostm | 1:d343cf676574 | 36 | myled3 = 0; // LED3 is OFF |
arostm | 1:d343cf676574 | 37 | myled4 = 1; // LED4 is ON |
arostm | 1:d343cf676574 | 38 | wait(tempo); // wait tempo |
arostm | 1:d343cf676574 | 39 | myled4 = 0; // LED4 is OFF |
arostm | 1:d343cf676574 | 40 | } |
arostm | 1:d343cf676574 | 41 | } |