Switch and LED stuff

Dependencies:   mbed

main.cpp

Committer:
Thawedmind
Date:
2019-10-15
Revision:
0:3f51bbc1f1a4

File content as of revision 0:3f51bbc1f1a4:


#include "mbed.h"

DigitalOut  red_led(D7);
DigitalOut  yellow_led(D6);
DigitalOut  green_led(D5);
DigitalIn   SW1(D4);

int main()
{

    //Switch on Yellow and Green to indicate
    //that the code is running
    yellow_led = 1;
    green_led = 1;
    red_led = 0; //Set RED LED to OFF

    while (1) {

        // Wait for SW1 to be pressed
        while (SW1 == 0) { }
        wait(0.2);

        red_led = 1;    //Turn ON LED

        while (SW1 == 1) { }
        wait(0.2);

        while (SW1 == 0) { }
        wait(0.2);

        red_led = 0;    //Turn ON LED

        while (SW1 == 1) { }
        wait(0.2);

    }

    //Repeat forever
}