
Task 3.4.4 Solution
Fork of Task344Solution by
main.cpp@2:7d9f93c3d682, 2019-09-18 (annotated)
- Committer:
- noutram
- Date:
- Wed Sep 18 12:43:44 2019 +0000
- Revision:
- 2:7d9f93c3d682
- Parent:
- 0:eebd090fb610
2019
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 | 2:7d9f93c3d682 | 3 | #ifdef TARGET_NUCLEO_F429ZI |
noutram | 2:7d9f93c3d682 | 4 | //#define ONBOARD |
noutram | 2:7d9f93c3d682 | 5 | #endif |
noutram | 2:7d9f93c3d682 | 6 | |
noutram | 2:7d9f93c3d682 | 7 | #ifdef ONBOARD |
noutram | 2:7d9f93c3d682 | 8 | BusOut binaryOutput(LED1, LED2, LED3); |
noutram | 2:7d9f93c3d682 | 9 | #else |
noutram | 0:eebd090fb610 | 10 | //Global objects |
noutram | 0:eebd090fb610 | 11 | BusOut binaryOutput(D5, D6, D7); |
noutram | 2:7d9f93c3d682 | 12 | #endif |
noutram | 0:eebd090fb610 | 13 | |
noutram | 0:eebd090fb610 | 14 | |
noutram | 0:eebd090fb610 | 15 | //Main function |
noutram | 0:eebd090fb610 | 16 | int main() { |
noutram | 0:eebd090fb610 | 17 | |
noutram | 0:eebd090fb610 | 18 | //Create a variable to hold the bit pattern |
noutram | 0:eebd090fb610 | 19 | unsigned int u; |
noutram | 0:eebd090fb610 | 20 | |
noutram | 0:eebd090fb610 | 21 | while(1) { |
noutram | 0:eebd090fb610 | 22 | |
noutram | 0:eebd090fb610 | 23 | u = 1; //Set initial value 0 |
noutram | 0:eebd090fb610 | 24 | int count = 0; |
noutram | 0:eebd090fb610 | 25 | while (count++ < 3) { |
noutram | 0:eebd090fb610 | 26 | binaryOutput = u; //Write to LEDs |
noutram | 0:eebd090fb610 | 27 | u = u << 1; //Shift left 1 bit |
noutram | 0:eebd090fb610 | 28 | wait(0.25); //Wait |
noutram | 0:eebd090fb610 | 29 | } |
noutram | 0:eebd090fb610 | 30 | |
noutram | 0:eebd090fb610 | 31 | //At this point, the output is binary 100 |
noutram | 0:eebd090fb610 | 32 | //Change to 010 |
noutram | 0:eebd090fb610 | 33 | binaryOutput = 2; //The missing yellow state |
noutram | 0:eebd090fb610 | 34 | wait(0.25); |
noutram | 0:eebd090fb610 | 35 | |
noutram | 0:eebd090fb610 | 36 | //The sequence can now repeat |
noutram | 0:eebd090fb610 | 37 | } //end while(1) |
noutram | 0:eebd090fb610 | 38 | } //end main |