
Task 3.4.4
Dependencies: mbed
main.cpp@0:6485cc607fa3, 2015-09-24 (annotated)
- Committer:
- noutram
- Date:
- Thu Sep 24 12:27:22 2015 +0000
- Revision:
- 0:6485cc607fa3
Initial version 24-09-2015
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:6485cc607fa3 | 1 | #include "mbed.h" |
noutram | 0:6485cc607fa3 | 2 | |
noutram | 0:6485cc607fa3 | 3 | //Global objects |
noutram | 0:6485cc607fa3 | 4 | BusOut binaryOutput(D5, D6, D7); |
noutram | 0:6485cc607fa3 | 5 | |
noutram | 0:6485cc607fa3 | 6 | |
noutram | 0:6485cc607fa3 | 7 | //Main function |
noutram | 0:6485cc607fa3 | 8 | int main() { |
noutram | 0:6485cc607fa3 | 9 | |
noutram | 0:6485cc607fa3 | 10 | //Create a variable to hold the bit pattern |
noutram | 0:6485cc607fa3 | 11 | unsigned int u; |
noutram | 0:6485cc607fa3 | 12 | |
noutram | 0:6485cc607fa3 | 13 | while(1) { |
noutram | 0:6485cc607fa3 | 14 | |
noutram | 0:6485cc607fa3 | 15 | u = 1; //Set initial value 0 |
noutram | 0:6485cc607fa3 | 16 | int count = 0; |
noutram | 0:6485cc607fa3 | 17 | while (count++ < 3) { |
noutram | 0:6485cc607fa3 | 18 | binaryOutput = u; //Write to LEDs |
noutram | 0:6485cc607fa3 | 19 | u = u << 1; //Shift left 1 bit |
noutram | 0:6485cc607fa3 | 20 | wait(0.25); //Wait |
noutram | 0:6485cc607fa3 | 21 | } |
noutram | 0:6485cc607fa3 | 22 | |
noutram | 0:6485cc607fa3 | 23 | //TODO: Make the pattern shift in the opposite direction |
noutram | 0:6485cc607fa3 | 24 | // (also known as the knight rider pattern) |
noutram | 0:6485cc607fa3 | 25 | |
noutram | 0:6485cc607fa3 | 26 | |
noutram | 0:6485cc607fa3 | 27 | } //end while(1) |
noutram | 0:6485cc607fa3 | 28 | } //end main |