LEDs and user button example.

Dependencies:   mbed

Committer:
arostm
Date:
Wed May 17 16:43:49 2017 +0200
Revision:
0:b385f231a65a
Child:
1:8932d9db4aaf
Creation of the blink leds exemple for the DISCO_F413ZH board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
arostm 0:b385f231a65a 1 #include "mbed.h"
arostm 0:b385f231a65a 2
arostm 0:b385f231a65a 3 DigitalOut myled1(LED1);
arostm 0:b385f231a65a 4 DigitalOut myled2(LED2);
arostm 0:b385f231a65a 5 DigitalOut myled3(LED3);
arostm 0:b385f231a65a 6
arostm 0:b385f231a65a 7 InterruptIn mybutton(USER_BUTTON);
arostm 0:b385f231a65a 8
arostm 0:b385f231a65a 9 double tempo = 0.2; //time to wait
arostm 0:b385f231a65a 10
arostm 0:b385f231a65a 11 void changetempo() {
arostm 0:b385f231a65a 12 if(tempo == 0.2) // If leds have low frequency
arostm 0:b385f231a65a 13 tempo = 0.1; // Set the fast frequency
arostm 0:b385f231a65a 14 else // If les have fast frequency
arostm 0:b385f231a65a 15 tempo = 0.2; // Set the low frequency
arostm 0:b385f231a65a 16 }
arostm 0:b385f231a65a 17
arostm 0:b385f231a65a 18 int main() {
arostm 0:b385f231a65a 19 myled1 = 0; //LED1 is OFF
arostm 0:b385f231a65a 20 myled2 = 0; //LED2 is OFF
arostm 0:b385f231a65a 21 myled3 = 0; //LED3 is OFF
arostm 0:b385f231a65a 22
arostm 0:b385f231a65a 23 mybutton.fall(&changetempo); //Interrupt to change tempo
arostm 0:b385f231a65a 24
arostm 0:b385f231a65a 25 while(1) {
arostm 0:b385f231a65a 26 myled1 = 1; // LED2 is ON
arostm 0:b385f231a65a 27 wait(tempo); // wait tempo
arostm 0:b385f231a65a 28 myled1 = 0; // LED2 is OFF
arostm 0:b385f231a65a 29 myled2 = 1; // LED1 is ON
arostm 0:b385f231a65a 30 wait(tempo); // wait tempo
arostm 0:b385f231a65a 31 myled2 = 0; // LED1 is OFF
arostm 0:b385f231a65a 32 myled3 = 1; // LED3 is ON
arostm 0:b385f231a65a 33 wait(tempo); // wait tempo
arostm 0:b385f231a65a 34 myled3 = 0; // LED3 is OFF
arostm 0:b385f231a65a 35 }
arostm 0:b385f231a65a 36 }
arostm 0:b385f231a65a 37