Christian Lerche
/
GrayCount
Simple upcounter, like binary, but in graycode, using onboard LEDs
main.cpp@0:966104be261b, 2009-12-05 (annotated)
- Committer:
- Lerche
- Date:
- Sat Dec 05 19:21:03 2009 +0000
- Revision:
- 0:966104be261b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Lerche | 0:966104be261b | 1 | /* |
Lerche | 0:966104be261b | 2 | |
Lerche | 0:966104be261b | 3 | Author: Christian Lerche |
Lerche | 0:966104be261b | 4 | Date: 05-12-2009 |
Lerche | 0:966104be261b | 5 | MCU: LPC1768 |
Lerche | 0:966104be261b | 6 | Notes: Simple graycode upcounter, using onboard LEDs. |
Lerche | 0:966104be261b | 7 | |
Lerche | 0:966104be261b | 8 | */ |
Lerche | 0:966104be261b | 9 | |
Lerche | 0:966104be261b | 10 | #include "mbed.h" |
Lerche | 0:966104be261b | 11 | |
Lerche | 0:966104be261b | 12 | BusOut LEDs(LED4, LED3, LED2, LED1); // Make 4 bit bus with LEDs |
Lerche | 0:966104be261b | 13 | unsigned char i; // Char to read for LEDs |
Lerche | 0:966104be261b | 14 | |
Lerche | 0:966104be261b | 15 | int main() { // Main structure |
Lerche | 0:966104be261b | 16 | i=0; // initialize i to 0 |
Lerche | 0:966104be261b | 17 | while(1) { // While-loop (Do forever) |
Lerche | 0:966104be261b | 18 | LEDs=i^(i>>1); // This converts the binary to graycode |
Lerche | 0:966104be261b | 19 | wait(0.5); // Wait for .5 seconds |
Lerche | 0:966104be261b | 20 | i=i+1; // Every loop, add one to i |
Lerche | 0:966104be261b | 21 | if(i==16) { // If i is 16, make i 0 |
Lerche | 0:966104be261b | 22 | i=0; // This makes it 0 |
Lerche | 0:966104be261b | 23 | } // End of if |
Lerche | 0:966104be261b | 24 | } // End of while-loop (Do not anymore) |
Lerche | 0:966104be261b | 25 | } // End of main structure |