Christian Lerche
/
GrayCount
Simple upcounter, like binary, but in graycode, using onboard LEDs
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* 00002 00003 Author: Christian Lerche 00004 Date: 05-12-2009 00005 MCU: LPC1768 00006 Notes: Simple graycode upcounter, using onboard LEDs. 00007 00008 */ 00009 00010 #include "mbed.h" 00011 00012 BusOut LEDs(LED4, LED3, LED2, LED1); // Make 4 bit bus with LEDs 00013 unsigned char i; // Char to read for LEDs 00014 00015 int main() { // Main structure 00016 i=0; // initialize i to 0 00017 while(1) { // While-loop (Do forever) 00018 LEDs=i^(i>>1); // This converts the binary to graycode 00019 wait(0.5); // Wait for .5 seconds 00020 i=i+1; // Every loop, add one to i 00021 if(i==16) { // If i is 16, make i 0 00022 i=0; // This makes it 0 00023 } // End of if 00024 } // End of while-loop (Do not anymore) 00025 } // End of main structure
Generated on Tue Jul 19 2022 10:00:59 by 1.7.2