Updated

Dependencies:   mbed

main.cpp

Committer:
ongjiajun
Date:
2019-02-15
Revision:
4:6e4d8744e5fb
Parent:
3:a1439fe436e9

File content as of revision 4:6e4d8744e5fb:

#include "mbed.h"
 
DigitalOut myled(LED1);
InterruptIn  button1(USER_BUTTON);
 
bool active = false;
 
void BUTTON_ISR(){
    active = !active;
}
 
int main() {
    // Set up
    button1.mode(PullUp);
    button1.fall(&BUTTON_ISR);
    while (1){
            if (button1 == 0){
                myled = 1; // LED is ON
                wait(0.2); // 200 ms
                myled = 0; // LED is OFF
                wait(0.2); // 200 ms
                myled = 1; 
                wait(0.2); 
                myled = 0; 
                wait(0.2); 
                myled = 1; 
                wait(0.2); 
                myled = 0; 
                wait(0.2); 
                }else if (button1 == 0){
                    myled = 1; // LED is ON
                    wait(0.2); // 200 ms
                    myled = 0; // LED is OFF
                    wait(0.2); // 200 ms
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2); 
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2);
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2); 
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2);
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2); 
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2);
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2); 
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2);
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2); 
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2);
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2); 
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2);
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2);
                    myled = 1; 
                    wait(0.2); 
                    myled = 0; 
                    wait(0.2);
                    }else {
                        myled = 0;}
        }         
        __wfi();    //Wait for interruptions
        
}