![](/media/cache/group/Embedded_software_in_context_icon.png.50x50_q85.png)
Task 3.4.4 Solution
Dependencies: mbed
main.cpp@0:eebd090fb610, 2015-09-24 (annotated)
- Committer:
- noutram
- Date:
- Thu Sep 24 12:27:31 2015 +0000
- Revision:
- 0:eebd090fb610
Initial version 24-09-2015
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:eebd090fb610 | 1 | #include "mbed.h" |
noutram | 0:eebd090fb610 | 2 | |
noutram | 0:eebd090fb610 | 3 | //Global objects |
noutram | 0:eebd090fb610 | 4 | BusOut binaryOutput(D5, D6, D7); |
noutram | 0:eebd090fb610 | 5 | |
noutram | 0:eebd090fb610 | 6 | |
noutram | 0:eebd090fb610 | 7 | //Main function |
noutram | 0:eebd090fb610 | 8 | int main() { |
noutram | 0:eebd090fb610 | 9 | |
noutram | 0:eebd090fb610 | 10 | //Create a variable to hold the bit pattern |
noutram | 0:eebd090fb610 | 11 | unsigned int u; |
noutram | 0:eebd090fb610 | 12 | |
noutram | 0:eebd090fb610 | 13 | while(1) { |
noutram | 0:eebd090fb610 | 14 | |
noutram | 0:eebd090fb610 | 15 | u = 1; //Set initial value 0 |
noutram | 0:eebd090fb610 | 16 | int count = 0; |
noutram | 0:eebd090fb610 | 17 | while (count++ < 3) { |
noutram | 0:eebd090fb610 | 18 | binaryOutput = u; //Write to LEDs |
noutram | 0:eebd090fb610 | 19 | u = u << 1; //Shift left 1 bit |
noutram | 0:eebd090fb610 | 20 | wait(0.25); //Wait |
noutram | 0:eebd090fb610 | 21 | } |
noutram | 0:eebd090fb610 | 22 | |
noutram | 0:eebd090fb610 | 23 | //At this point, the output is binary 100 |
noutram | 0:eebd090fb610 | 24 | //Change to 010 |
noutram | 0:eebd090fb610 | 25 | binaryOutput = 2; //The missing yellow state |
noutram | 0:eebd090fb610 | 26 | wait(0.25); |
noutram | 0:eebd090fb610 | 27 | |
noutram | 0:eebd090fb610 | 28 | //The sequence can now repeat |
noutram | 0:eebd090fb610 | 29 | } //end while(1) |
noutram | 0:eebd090fb610 | 30 | } //end main |