Stage-1 Students SoCEM / Mbed 2 deprecated Task322Solution

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  red_led(D7);
00004 DigitalOut  yellow_led(D6);
00005 DigitalOut  green_led(D5);
00006 DigitalIn   SW1(D4);
00007 
00008 //This is the solution based on the proposed flowchart.
00009 //It is flawed however (see next exercise) due to
00010 //switch bounce.
00011 
00012 int main() {
00013 
00014     //Switch on Yellow and Green to indicate
00015     //that the code is running
00016     yellow_led = 1;
00017     green_led = 1;
00018     red_led = 0; //Set RED LED to OFF
00019     
00020     // Wait for SW1 to be pressed
00021     while (SW1 == 0) { }
00022     
00023     // Wait for SW1 to be released
00024     while (SW1 == 1) { }
00025     
00026     red_led = 1;    //Turn ON LED
00027     
00028     while (1) { }       //Repeat forever
00029 }