Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MCP23017 TCS3472_I2C WattBob_TextLCD mbed-rtos mbed
mbedLCD.h
00001 #include "MCP23017.h" 00002 #include "WattBob_TextLCD.h" 00003 #define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT) 00004 #define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT) 00005 #include <string> 00006 #include "chipNumbers.h" 00007 MCP23017 *par_port; 00008 WattBob_TextLCD *lcd; 00009 00010 /* void printLCD(const char * text) 00011 * Take a character array and split and trim it into two lines, to be displayed on the WattBob LCD screen. 00012 */ 00013 void printLCD(const char * text) 00014 { 00015 std::string txt_str = std::string(text); //Convert ther character array to a std::string, 00016 //to use in the string manipulation functions. 00017 lcd->reset(); 00018 if(txt_str.length() > 32) { 00019 int length = txt_str.length(); 00020 txt_str = txt_str.erase(32,length-32); 00021 lcd->locate(0,0); //Going to new line 00022 text = txt_str.c_str(); 00023 } 00024 if(txt_str.length() > 16) { 00025 string line1 = txt_str.substr(0,16); 00026 string line2 = txt_str.substr(16,16); 00027 lcd->locate(0,0); //Going to new line 00028 lcd->printf(line1.c_str()); 00029 lcd->locate(1,0); //Going to new line 00030 lcd->printf(line2.c_str()); 00031 lcd->locate(0,0); //Going to new line 00032 } 00033 if(txt_str.length() <= 16) { 00034 lcd->locate(0,0); 00035 lcd->printf(text); 00036 } 00037 00038 } 00039 00040 /* void printLCD(string txt_str) 00041 * Take a string and split and trim it into two lines, to be displayed on the WattBob LCD screen. 00042 */ 00043 void printLCD(string txt_str) 00044 { 00045 lcd->reset(); 00046 if(txt_str.length() > 32) { 00047 int length = txt_str.length(); 00048 txt_str = txt_str.erase(32,length-32); 00049 lcd->locate(0,0); //Going to new line 00050 00051 } 00052 if(txt_str.length() > 16) { 00053 string line1 = txt_str.substr(0,16); 00054 string line2 = txt_str.substr(16,16); 00055 lcd->locate(0,0); //Going to new line 00056 lcd->printf(line1.c_str()); 00057 lcd->locate(1,0); //Going to new line 00058 lcd->printf(line2.c_str()); 00059 lcd->locate(0,0); //Going to new line 00060 } 00061 if(txt_str.length() <= 16) { 00062 lcd->locate(0,0); 00063 lcd->printf(&txt_str[0]); 00064 } 00065 00066 } 00067 /* void setupLCD() 00068 * Setup the I2C communication line to the WattBob. 00069 */ 00070 void setupLCD() 00071 { 00072 par_port = new MCP23017(p9, p10, 0x40); 00073 par_port->config(0x0F00, 0x0F00, 0x0F00); // configure MCP23017 chip on WattBob 00074 BACK_LIGHT_ON(par_port); 00075 lcd = new WattBob_TextLCD(par_port); 00076 lcd->reset(); 00077 } 00078 /* void printStoresChipValues() 00079 * Print out the values of the stored chip values to the LCD. 00080 */ 00081 void printStoredChipValues() 00082 { 00083 stringstream strs; 00084 strs << "Stored chip values"; 00085 strs << "R:"; 00086 strs << redAmount; 00087 strs << ", G:"; 00088 strs << greenAmount; 00089 strs << ", B:"; 00090 strs << blueAmount; 00091 string temp_str = strs.str(); 00092 char const* pchar = temp_str.c_str(); 00093 printLCD(pchar); 00094 }
Generated on Thu Jul 14 2022 19:06:18 by
1.7.2