LEDs/Button example.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 1:d343cf676574
- Parent:
- 0:2bd4c0051d9a
- Child:
- 2:603a8ac68090
--- a/main.cpp Tue May 16 17:03:58 2017 +0200 +++ b/main.cpp Wed May 17 09:17:45 2017 +0200 @@ -1,5 +1,41 @@ #include "mbed.h" -int main() -{ +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +InterruptIn mybutton(USER_BUTTON); + +double tempo = 0.2; //time to wait + +void changetempo() { + if(tempo == 0.2) // If leds have low frequency + tempo = 0.1; // Set the fast frequency + else // If les have fast frequency + tempo = 0.2; // Set the low frequency } + +int main() { + myled1 = 0; //LED1 is OFF + myled2 = 0; //LED2 is OFF + myled3 = 0; //LED3 is OFF + myled4 = 0; //LED4 is OFF + + mybutton.fall(&changetempo); //Interrupt to change tempo + + while(1) { + myled2 = 1; // LED2 is ON + wait(tempo); // wait tempo + myled2 = 0; // LED2 is OFF + myled1 = 1; // LED1 is ON + wait(tempo); // wait tempo + myled1 = 0; // LED1 is OFF + myled3 = 1; // LED3 is ON + wait(tempo); // wait tempo + myled3 = 0; // LED3 is OFF + myled4 = 1; // LED4 is ON + wait(tempo); // wait tempo + myled4 = 0; // LED4 is OFF + } +}