Task 1.3.3 Solution

Committer:
noutram
Date:
Thu Jul 13 14:46:55 2017 +0000
Revision:
1:66359c8bfea0
Parent:
0:ea9d3e7bd1e5
updated for mbed-os 5.5

Who changed what in which revision?

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