Simple upcounter, like binary, but in graycode, using onboard LEDs

Dependencies:   mbed

main.cpp

Committer:
Lerche
Date:
2009-12-05
Revision:
0:966104be261b

File content as of revision 0:966104be261b:

/*

Author: Christian Lerche
Date: 05-12-2009
MCU: LPC1768
Notes: Simple graycode upcounter, using onboard LEDs.

*/

#include "mbed.h"

BusOut LEDs(LED4, LED3, LED2, LED1);        // Make 4 bit bus with LEDs
unsigned char i;                            // Char to read for LEDs

int main() {                                // Main structure
    i=0;                                    // initialize i to 0
    while(1) {                              // While-loop (Do forever)
        LEDs=i^(i>>1);                      // This converts the binary to graycode
        wait(0.5);                          // Wait for .5 seconds
        i=i+1;                              // Every loop, add one to i
        if(i==16) {                         // If i is 16, make i 0
            i=0;                            // This makes it 0
        }                                   // End of if
    }                                       // End of while-loop (Do not anymore)
}                                           // End of main structure