Task 1.3.4 Solution

Dependencies:   mbed

Committer:
noutram
Date:
Thu Sep 24 12:24:54 2015 +0000
Revision:
0:b248b671f558
Initial version 24-09-2015

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:b248b671f558 1 //This is known as a “header file”
noutram 0:b248b671f558 2 //In short, this copies and pastes the text file
noutram 0:b248b671f558 3 //mbed.h into this code
noutram 0:b248b671f558 4 #include "mbed.h"
noutram 0:b248b671f558 5
noutram 0:b248b671f558 6 #define kRED 1
noutram 0:b248b671f558 7 #define kYELLOW 2
noutram 0:b248b671f558 8 #define kGREEN 4
noutram 0:b248b671f558 9
noutram 0:b248b671f558 10 BusOut binaryOutput(D7, D6, D5); //Outputs as an integer
noutram 0:b248b671f558 11
noutram 0:b248b671f558 12 //The main function - all executable C / C++
noutram 0:b248b671f558 13 //applications have a main function. This is
noutram 0:b248b671f558 14 //out entry point in the software
noutram 0:b248b671f558 15 Ticker T;
noutram 0:b248b671f558 16
noutram 0:b248b671f558 17 int main() {
noutram 0:b248b671f558 18
noutram 0:b248b671f558 19 binaryOutput = 0;
noutram 0:b248b671f558 20
noutram 0:b248b671f558 21 // ALL the code is contained in a
noutram 0:b248b671f558 22 // “while loop"
noutram 0:b248b671f558 23
noutram 0:b248b671f558 24 // THIS IS NOT AN IDEAL SOLUTION. HOWEVER IT IS SIMPLE
noutram 0:b248b671f558 25
noutram 0:b248b671f558 26
noutram 0:b248b671f558 27 while(1)
noutram 0:b248b671f558 28 {
noutram 0:b248b671f558 29 //The code between the { curly braces }
noutram 0:b248b671f558 30 //is the code that is repeated
noutram 0:b248b671f558 31
noutram 0:b248b671f558 32 //STATE 1 (R)
noutram 0:b248b671f558 33 binaryOutput = kRED;
noutram 0:b248b671f558 34 wait(1.0);
noutram 0:b248b671f558 35
noutram 0:b248b671f558 36 //STATE 2 (RA)
noutram 0:b248b671f558 37 binaryOutput = kRED + kYELLOW;
noutram 0:b248b671f558 38 wait(1.0);
noutram 0:b248b671f558 39
noutram 0:b248b671f558 40 //STATE 3 (G)
noutram 0:b248b671f558 41 binaryOutput = kGREEN;
noutram 0:b248b671f558 42 wait(1.0);
noutram 0:b248b671f558 43
noutram 0:b248b671f558 44 //STATES 4-7 (Flashing A)
noutram 0:b248b671f558 45 binaryOutput = kYELLOW;
noutram 0:b248b671f558 46 wait(0.25);
noutram 0:b248b671f558 47 binaryOutput = 0;
noutram 0:b248b671f558 48 wait(0.25);
noutram 0:b248b671f558 49 binaryOutput = kYELLOW;
noutram 0:b248b671f558 50 wait(0.25);
noutram 0:b248b671f558 51 binaryOutput = 0;
noutram 0:b248b671f558 52 wait(0.25);
noutram 0:b248b671f558 53
noutram 0:b248b671f558 54 }
noutram 0:b248b671f558 55 }