// Sparkfun Display Driver via Software Serial // Tim Hirzel // // This is adapted from the code by aaronpropst in Feb 2007 available here // http://www.arduino.cc/playground/Learning/SparkFunSerLCD // and the SoftwareSerial library and example code by David A. Mellis in 2006 #include float currentBrightness; SoftwareSerial LCD = SoftwareSerial(DISPLAY_RXPIN, DISPLAY_TXPIN); byte pinState = 0; void lcdPrint(char * str) { LCD.print(str); } void lcdPrint(int i) { LCD.print(i); } void lcdPrint(byte i) { LCD.print(i, BYTE); } void setupDisplay() { pinMode(DISPLAY_RXPIN, INPUT); pinMode(DISPLAY_TXPIN, OUTPUT); // set the data rate for the SoftwareSerial port LCD.begin(9600); delay(2); // these delays seem to help the display } void selectDisplayLineOne(){ //puts the cursor at line 0 char 0. startSerialCommand(); //command flag LCD.print(128, BYTE); //position } void selectDisplayLineTwo(){ //puts the cursor at line 0 char 0. startSerialCommand(); //command flag LCD.print(192, BYTE); //position } void clearLCD(){ startSerialCommand(); //command flag LCD.print(0x01, BYTE); //clear command. } void lcdBacklightOn(){ //turns on the backlight startDisplayCommand(); //command flag for backlight stuff LCD.print(157, BYTE); //light level. delay(2); } void lcdBacklightOff(){ //turns off the backlight startDisplayCommand(); //command flag for backlight stuff LCD.print(130, BYTE); //light level for off. 128 = totally off. increase value to add brightness delay(2); } void startSerialCommand(){ //a general function to call the command flag for issuing all other commands LCD.print(0xFE, BYTE); } void startDisplayCommand(){ //a general function to call the command flag for issuing all other commands LCD.print(0x7C, BYTE); } /* float lcdGetBrightness() { return currentBrightness; } void setCurrentScreenAsSplash() { LCD.print(0xFE, BYTE); LCD.print(10, BYTE); } void toggleSplash() { LCD.print(0xFE, BYTE); LCD.print(9, BYTE); } void underlineCursorOn(boolean on) { LCD.print(0xFE, BYTE); if (on) LCD.print(74, BYTE); else LCD.print(75, BYTE); } void cursorSet(int xpos, int ypos){ LCD.print(0xFE, BYTE); LCD.print(71, BYTE); LCD.print(xpos); //Column position LCD.print(ypos); //Row position } void customChar(byte address, byte *charmap){ int i; clearLCD(); LCD.print(254, BYTE); LCD.print(address+64, BYTE); for (i =0; i< 8; i++){ LCD.print(charmap[i], BYTE); } clearLCD(); } void printCustom(byte address) { LCD.print(address, BYTE); } void lcdSetBrightness(float percent){ //turns off the backlight currentBrightness = percent; byte newval = 128 + (byte)(29.0 * percent * 0.01); LCD.print(0x7C, BYTE); //command flag for backlight stuff LCD.print(newval, BYTE); //light level for off. delay(4); } */