Aaryn Smith / Mbed 2 deprecated LCDtest

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 DigitalOut myled(LED1);
00004 Serial pc(USBTX, USBRX);
00005 Serial lcd(p13, p14);
00006 
00007 void clearLCD() {
00008     lcd.printf("%c%c",0xFE,0x01);
00009 }
00010 void setLCDpos(int xpos, int ypos) {
00011     int pos = 0x80;
00012     switch (xpos){
00013     case 1: 
00014         pos +=0; 
00015         break;
00016     case 2: 
00017         pos +=64; 
00018         break;
00019     case 3: 
00020         pos +=20; 
00021         break;
00022     case 4: 
00023         pos +=84;
00024         break;
00025     }
00026     pos += (ypos-1);
00027     lcd.printf("%c%c",0xFE,pos);
00028 }
00029 void setBrightness(int lev) {
00030     lcd.printf("%c%c",0x7C,lev+127);
00031     wait(.1);
00032 }
00033 int main() {
00034     wait(2);
00035     clearLCD();
00036     unsigned int i=0;
00037     setLCDpos(1,1);
00038     lcd.printf("Hello, World!");
00039     setLCDpos(2,1);
00040     lcd.printf("Led");
00041     while (1) {
00042         wait(.2);
00043         i++;
00044         myled = !myled;
00045         setLCDpos(2,5);
00046         if (myled) {
00047             lcd.printf("On ");
00048         } else {
00049             lcd.printf("Off");
00050         }
00051         setLCDpos(2,9);
00052         lcd.printf("#%7i",i);
00053     }
00054 }