Task 3.2.3

Committer:
noutram
Date:
Thu Sep 24 12:25:45 2015 +0000
Revision:
0:1d174f559653
Initial version 24-09-2015

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:1d174f559653 1 #include "mbed.h"
noutram 0:1d174f559653 2
noutram 0:1d174f559653 3 DigitalOut red_led(D7);
noutram 0:1d174f559653 4 DigitalOut yellow_led(D6);
noutram 0:1d174f559653 5 DigitalOut green_led(D5);
noutram 0:1d174f559653 6 DigitalIn SW1(D4);
noutram 0:1d174f559653 7
noutram 0:1d174f559653 8 //This is the solution based on the proposed flowchart.
noutram 0:1d174f559653 9 //The precise delay required may need adjusting
noutram 0:1d174f559653 10
noutram 0:1d174f559653 11 int main() {
noutram 0:1d174f559653 12
noutram 0:1d174f559653 13 //Switch on Yellow and Green to indicate
noutram 0:1d174f559653 14 //that the code is running
noutram 0:1d174f559653 15 yellow_led = 1;
noutram 0:1d174f559653 16 green_led = 1;
noutram 0:1d174f559653 17 red_led = 0; //Set RED LED to OFF
noutram 0:1d174f559653 18
noutram 0:1d174f559653 19 // Wait for SW1 to be pressed
noutram 0:1d174f559653 20 while (SW1 == 0) { }
noutram 0:1d174f559653 21
noutram 0:1d174f559653 22 //Insert a small delay to reduce switch bounce effects
noutram 0:1d174f559653 23 wait(0.05);
noutram 0:1d174f559653 24
noutram 0:1d174f559653 25 // Wait for SW1 to be released
noutram 0:1d174f559653 26 while (SW1 == 1) { }
noutram 0:1d174f559653 27
noutram 0:1d174f559653 28 red_led = 1; //Turn ON LED
noutram 0:1d174f559653 29
noutram 0:1d174f559653 30 while (1) { } //Repeat forever
noutram 0:1d174f559653 31 }