Ellie Griffiths / Mbed 2 deprecated SimpleCounter

Dependencies:   TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "TextLCD.h"
00003 #include "DebouncedIn.h"
00004 
00005 BusOut led(LED4, LED3, LED2, LED1);
00006 unsigned char i;
00007 TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7
00008 DebouncedIn setbutton(p5);
00009 
00010 int main() {
00011     int state;
00012     state = 0;
00013     i = 0;
00014     while(1) {
00015         if (setbutton.rising()) {
00016             state = !state;
00017         }
00018         if (state == 0) {
00019             lcd.printf("Binary: %u\n", i);
00020             led = i;
00021         }
00022         else if (state == 1) {
00023             lcd.printf("Graycode: %u\n", i);
00024             led = i^(i>>1);
00025         }
00026         wait(1);
00027         i = i+1;
00028         if (i == 16) {
00029             i = 0;
00030         }
00031         lcd.cls();    
00032     }
00033 }