Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:e2f876895db4, 2015-09-24 (annotated)
- Committer:
- noutram
- Date:
- Thu Sep 24 12:27:59 2015 +0000
- Revision:
- 0:e2f876895db4
Initial version 24-09-2015
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| noutram | 0:e2f876895db4 | 1 | #include "mbed.h" |
| noutram | 0:e2f876895db4 | 2 | |
| noutram | 0:e2f876895db4 | 3 | //Global objects |
| noutram | 0:e2f876895db4 | 4 | BusOut binaryOutput(D5, D6, D7); //Outputs as an integer |
| noutram | 0:e2f876895db4 | 5 | //BusIn binaryInput(D3, D4); //Inputs as an integer |
| noutram | 0:e2f876895db4 | 6 | DigitalIn SW1(D3); |
| noutram | 0:e2f876895db4 | 7 | DigitalIn SW2(D4); |
| noutram | 0:e2f876895db4 | 8 | |
| noutram | 0:e2f876895db4 | 9 | //Main function |
| noutram | 0:e2f876895db4 | 10 | int main() { |
| noutram | 0:e2f876895db4 | 11 | |
| noutram | 0:e2f876895db4 | 12 | //Create a variable to hold the bit pattern |
| noutram | 0:e2f876895db4 | 13 | unsigned int u = 7; |
| noutram | 0:e2f876895db4 | 14 | |
| noutram | 0:e2f876895db4 | 15 | while(1) { |
| noutram | 0:e2f876895db4 | 16 | |
| noutram | 0:e2f876895db4 | 17 | binaryOutput = u; //Write to LEDs |
| noutram | 0:e2f876895db4 | 18 | |
| noutram | 0:e2f876895db4 | 19 | //TOGGLE all 3 bits in u |
| noutram | 0:e2f876895db4 | 20 | u = u ^ 7; |
| noutram | 0:e2f876895db4 | 21 | |
| noutram | 0:e2f876895db4 | 22 | //Calculate the delay |
| noutram | 0:e2f876895db4 | 23 | int binaryInput = SW1 + (SW2 << 1); |
| noutram | 0:e2f876895db4 | 24 | double delay = (double)(binaryInput+1); |
| noutram | 0:e2f876895db4 | 25 | wait(delay * 0.25); //Wait |
| noutram | 0:e2f876895db4 | 26 | |
| noutram | 0:e2f876895db4 | 27 | } //end while(1) |
| noutram | 0:e2f876895db4 | 28 | } //end main |