Code for RFID Robot
Dependencies: DebounceIn HTTPClient ID12RFID SDFileSystem TextLCD WiflyInterface iniparser mbed
LCDText.cpp
00001 #include "LCDText.h" 00002 00003 void clearLCD() { 00004 char buff[33]; 00005 memset(buff, ' ', 32); 00006 buff[32] = '\0'; 00007 mylcd.printf(buff); 00008 } 00009 00010 //clears LCD and prints the two strings centered on each line 00011 //max length of each string is 16 00012 void printLCD(const char* string1, const char* string2) { 00013 char buff[33]; 00014 memset(buff, ' ', 32); 00015 buff[32] = '\0'; 00016 //clear LCD 00017 clearLCD(); 00018 00019 //print to LCD 00020 if(string1) { 00021 memcpy(buff+(16-strlen(string1))/2, string1, strlen(string1)); 00022 } 00023 if(string2) { 00024 memcpy(buff+16+(16-strlen(string2))/2, string2, strlen(string2)); 00025 } 00026 mylcd.printf(buff); 00027 } 00028 00029 //creates a menu with with a title, controlled by the up/down/select buttons 00030 //returns index of option selected 00031 int displayMenu(const char* menuTitle, const char** menuOptions, int numOptions) { 00032 int curSelection = 0; 00033 00034 printLCD(menuTitle, menuOptions[curSelection]); 00035 if(!up || !down || !select || !back) wait(.3); 00036 while(1) { 00037 if(!up) { 00038 curSelection = (curSelection == numOptions-1) ? 0 : (curSelection + 1); 00039 printLCD(menuTitle, menuOptions[curSelection]); 00040 if(!up) wait(.2); 00041 } 00042 if(!down) { 00043 curSelection = (curSelection == 0) ? (numOptions - 1) : (curSelection - 1); 00044 printLCD(menuTitle, menuOptions[curSelection]); 00045 if(!down) wait(.2); 00046 } 00047 if(!select) { 00048 clearLCD(); 00049 return curSelection; 00050 } 00051 if(!back) { 00052 clearLCD(); 00053 return -1; 00054 } 00055 } 00056 }
Generated on Tue Jul 12 2022 18:24:35 by 1.7.2