ST / Mbed 2 deprecated DISCO_F413ZH-blink-leds

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut myled1(LED1);
00004 DigitalOut myled2(LED2);
00005 DigitalOut myled3(LED3);
00006 
00007 InterruptIn mybutton(USER_BUTTON);
00008 
00009 double tempo = 0.2;    //time to wait
00010 
00011 void changetempo()
00012 {
00013     if(tempo == 0.2)   // If leds have low frequency
00014         tempo = 0.1;   // Set the fast frequency
00015     else               // If les have fast frequency
00016         tempo = 0.2;   // Set the low frequency
00017 }
00018 
00019 int main()
00020 {
00021     myled1 = 0;            //LED1 is OFF
00022     myled2 = 0;            //LED2 is OFF
00023     myled3 = 0;            //LED3 is OFF
00024 
00025     mybutton.fall(&changetempo);  //Interrupt to change tempo
00026 
00027     while(1) {
00028         myled1 = 1;   // LED2 is ON
00029         wait(tempo);  // wait tempo
00030         myled1 = 0;   // LED2 is OFF
00031         myled2 = 1;   // LED1 is ON
00032         wait(tempo);  // wait tempo
00033         myled2 = 0;   // LED1 is OFF
00034         myled3 = 1;   // LED3 is ON
00035         wait(tempo);  // wait tempo
00036         myled3 = 0;   // LED3 is OFF
00037     }
00038 }