Task 1.3.2 Solution

Committer:
noutram
Date:
Thu Jul 13 14:46:47 2017 +0000
Revision:
1:80b71726a20a
Parent:
0:8c84f2a81909
updated for mbed-os 5.5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:8c84f2a81909 1 //This is known as a “header file”
noutram 0:8c84f2a81909 2 //In short, this copies and pastes the text file
noutram 0:8c84f2a81909 3 //mbed.h into this code
noutram 0:8c84f2a81909 4 #include "mbed.h"
noutram 0:8c84f2a81909 5
noutram 0:8c84f2a81909 6 //Create a DigitalOut “object” called myled
noutram 0:8c84f2a81909 7 //Pass constant D7 as a “parameter”
noutram 0:8c84f2a81909 8 DigitalOut redLED(D7);
noutram 0:8c84f2a81909 9 DigitalOut yellowLED(D6);
noutram 0:8c84f2a81909 10 DigitalOut greenLED(D5);
noutram 0:8c84f2a81909 11
noutram 0:8c84f2a81909 12 //The main function - all executable C / C++
noutram 0:8c84f2a81909 13 //applications have a main function. This is
noutram 0:8c84f2a81909 14 //out entry point in the software
noutram 0:8c84f2a81909 15 int main() {
noutram 0:8c84f2a81909 16
noutram 0:8c84f2a81909 17 redLED = 0;
noutram 0:8c84f2a81909 18 yellowLED = 0;
noutram 0:8c84f2a81909 19 greenLED = 0;
noutram 0:8c84f2a81909 20
noutram 0:8c84f2a81909 21 // ALL the code is contained in a
noutram 0:8c84f2a81909 22 // “while loop"
noutram 0:8c84f2a81909 23
noutram 0:8c84f2a81909 24
noutram 0:8c84f2a81909 25 while(1)
noutram 0:8c84f2a81909 26 {
noutram 0:8c84f2a81909 27 //The code between the { curly braces }
noutram 0:8c84f2a81909 28 //is the code that is repeated
noutram 0:8c84f2a81909 29
noutram 0:8c84f2a81909 30 //STATE 1 (R)
noutram 0:8c84f2a81909 31 redLED = 1;
noutram 0:8c84f2a81909 32 yellowLED = 0;
noutram 0:8c84f2a81909 33 greenLED = 0;
noutram 0:8c84f2a81909 34 wait(1.0);
noutram 0:8c84f2a81909 35
noutram 0:8c84f2a81909 36 //STATE 2 (RA)
noutram 0:8c84f2a81909 37 yellowLED = 1;
noutram 0:8c84f2a81909 38 wait(1.0);
noutram 0:8c84f2a81909 39
noutram 0:8c84f2a81909 40 //STATE 3 (G)
noutram 0:8c84f2a81909 41 redLED = 0;
noutram 0:8c84f2a81909 42 yellowLED = 0;
noutram 0:8c84f2a81909 43 greenLED = 1;
noutram 0:8c84f2a81909 44 wait(1.0);
noutram 0:8c84f2a81909 45
noutram 0:8c84f2a81909 46 //STATE 4 (A)
noutram 0:8c84f2a81909 47 yellowLED = 1;
noutram 0:8c84f2a81909 48 greenLED = 0;
noutram 0:8c84f2a81909 49 wait(1.0);
noutram 0:8c84f2a81909 50 }
noutram 0:8c84f2a81909 51 }