sf_LCD - Another Serial LCD library
I've subclassed the SoftwareSerial class so that you can easily use the SparkFun SerLCD on other pins besides 1
UPDATE: my arduino projects are now hosted on GoogleCode now http://code.google.com/p/arduino-ajoslin/
NOTE: the code below is very out-of-date -- the version at google code supports multiple resolutions and brightness controls
Enjoy !
Al;
Example File: one.pde
/* NOTE: you must: #include <SoftwareSerial.h> BEFORE including the SparkFunSerLCD.h header */ #include <SoftwareSerial.h> #include <SparkFunSerLCD.h> SparkFunSerLCD led(2,2,16); // desired pin, rows, cols void setup () { led.setup(); delay(1000); led.at(1,4,"Milliseconds"); delay(1000); led.off(); delay(1000); led.on(); led.at(2,7,"m:"); for (int b=0; b<101; b+=5) { led.bright(b); b+=5; led.at(2,9,millis()); delay(500); } led.cursorBlock(); for (int x=5; x<9; x++) { led.pos(1,x); delay(500); } led.cursorUnderline(); for (int x=10; x<15; x++) { led.pos(1,x); delay(500); } led.cursorOff(); } void loop () { led.at(2,9,millis()); }
Header File: SparkFunSerLCD.h
/* NOTE: you must: #include <SoftwareSerial.h> BEFORE including the class header file allen joslin payson productions allen@joslin.net */ #ifndef SparkFunSerLCD_h #define SparkFunSerLCD_h #include "WProgram.h" /******************************************************************************************************/ /* SparkFunSerLCD -- manages the SparkFun SerLCD, based on SoftwareSerial to aid pinning and printing */ /* */ /* some cmds are cached so repeated calls will not actually be sent which can cause */ /* flickering of the display, printed values are not cached and are always sent */ /* */ /* autoOn: turn off the display and turn it back on with the next command */ /* */ /* posBase: cursor positioning via 0x0 or 1x1 */ /* */ /* on/off: display of characters, not backlight */ /* */ /* bright: backlight control, by percentage */ /* */ /* scrolling: scrolling is slow because of the amount of time the LCD takes to redraw. */ /* scrolling is persistant and moves the x-origin a single column at a time */ /* */ /******************************************************************************************************/ class SparkFunSerLCD : public SoftwareSerial { private: int _bv[9]; int _ro[5]; public: SparkFunSerLCD ( int pin, int numRows, int numCols, int posBase=1 ); void setup ( int brightPcnt=100, boolean startEmpty=true ); void on (); void off (); void empty (); void scrollLeft (); void scrollRight (); void bright ( int pcnt ); void pos ( int row, int col ); void cursorUnderline(); void cursorBlock(); void cursorOff (); // shortcuts for printing at particular positions void at ( int row, int col, char ); void at ( int row, int col, const char[] ); void at ( int row, int col, uint8_t ); void at ( int row, int col, int ); void at ( int row, int col, unsigned int ); void at ( int row, int col, long ); void at ( int row, int col, unsigned long ); void at ( int row, int col, long, int ); }; #endif
C++ Source File: SparkFunSerLCD.cpp
/* NOTE: you must: #include "SoftwareSerial.h" BEFORE including the class header file allen joslin payson productions allen@joslin.net */ #include "SoftwareSerial.h" #include "SparkFunSerLCD.h" /* ======================================================== */ #define PINOUT 0 #define POSBASE 1 #define BOUNCE 2 #define NUMROWS 3 #define NUMCOLS 4 #define LASTROW 5 #define LASTCOL 6 #define LASTBRIGHT 7 //-------------------------- SparkFunSerLCD::SparkFunSerLCD ( int pin, int numRows, int numCols, int posBase ) : SoftwareSerial(pin,pin) { _bv[PINOUT]=pin; _bv[POSBASE]=posBase; _bv[BOUNCE]=4; _bv[NUMROWS]=numRows; _bv[NUMCOLS]=numCols; _bv[LASTROW]=1; _bv[LASTCOL]=1; _bv[LASTBRIGHT]=100; _ro[0]=0; _ro[1]=64; _ro[2]=numCols; _ro[3]=_ro[1]+numCols; } //-------------------------- void SparkFunSerLCD::setup( int startPcnt, boolean startEmpty ) { pinMode(_bv[PINOUT], OUTPUT); delay(_bv[BOUNCE]); begin(9600); delay(_bv[BOUNCE]); if (startEmpty) { empty(); } bright(startPcnt); cursorOff(); } //-------------------------- void SparkFunSerLCD::on () { print(0xfe,BYTE); delay(_bv[BOUNCE]); print(0x0c,BYTE); delay(_bv[BOUNCE]); } //-------------------------- void SparkFunSerLCD::off () { print(0xfe,BYTE); delay(_bv[BOUNCE]); print(0x08,BYTE); delay(_bv[BOUNCE]); } //-------------------------- void SparkFunSerLCD::scrollLeft () { print(0xfe,BYTE); delay(_bv[BOUNCE]); print(0x18,BYTE); delay(_bv[BOUNCE]); } //-------------------------- void SparkFunSerLCD::scrollRight () { print(0xfe,BYTE); delay(_bv[BOUNCE]); print(0x1c,BYTE); delay(_bv[BOUNCE]); } //-------------------------- void SparkFunSerLCD::empty () { print(0xfe,BYTE); delay(_bv[BOUNCE]); print(0x01,BYTE); delay(_bv[BOUNCE]*10); } //-------------------------- void SparkFunSerLCD::cursorUnderline () { print(0xfe,BYTE); delay(_bv[BOUNCE]); print(0x0e,BYTE); delay(_bv[BOUNCE]); } //-------------------------- void SparkFunSerLCD::cursorBlock () { print(0xfe,BYTE); delay(_bv[BOUNCE]); print(0x0d,BYTE); delay(_bv[BOUNCE]); } //-------------------------- void SparkFunSerLCD::cursorOff () { print(0xfe,BYTE); delay(_bv[BOUNCE]); print(0x0c,BYTE); delay(_bv[BOUNCE]); } //-------------------------- void SparkFunSerLCD::bright ( int pcnt ) { if (_bv[LASTBRIGHT] == pcnt) { return; } pcnt = (pcnt<0)?0:pcnt; pcnt = (pcnt>100)?100:pcnt; print(0x7c,BYTE); delay(_bv[BOUNCE]); print(128+(pcnt*30/100),BYTE); delay(_bv[BOUNCE]); _bv[LASTBRIGHT] = pcnt; } //-------------------------- void SparkFunSerLCD::pos ( int row, int col ) { print(0xfe,BYTE); delay(_bv[BOUNCE]); print(0x80 + _ro[(row - _bv[POSBASE])] + (col - _bv[POSBASE]),BYTE); delay(_bv[BOUNCE]); } // shortcuts void SparkFunSerLCD::at ( int row, int col, char v ) { pos(row,col); print(v); } void SparkFunSerLCD::at ( int row, int col, const char v[] ) { pos(row,col); print(v); } void SparkFunSerLCD::at ( int row, int col, uint8_t v ) { pos(row,col); print(v); } void SparkFunSerLCD::at ( int row, int col, int v ) { pos(row,col); print(v); } void SparkFunSerLCD::at ( int row, int col, unsigned int v ) { pos(row,col); print(v); } void SparkFunSerLCD::at ( int row, int col, long v ) { pos(row,col); print(v); } void SparkFunSerLCD::at ( int row, int col, unsigned long v ) { pos(row,col); print(v); } void SparkFunSerLCD::at ( int row, int col, long v, int t ) { pos(row,col); print(v,t); } /* ======================================================== */