An interface to the Sparkfun Serial Graphic LCD, LCD-09351; and Graphic LCD Serial Backpack, LCD-09352. Derived class from Serial so that you can conveniently send text to the display with printf(), putc(), etc.
Diff: SerialGraphicLCD.h
- Revision:
- 0:a3d518d2f36f
- Child:
- 1:2f436b8aebf4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialGraphicLCD.h Wed Mar 28 16:04:25 2012 +0000 @@ -0,0 +1,131 @@ +/* Serial Graphics LCD Driver for Sparkfun Serial Graphics LCD, LCD-09351; and Graphic + * LCD Serial Backpack, LCD-09352. + * + * @author Michael Shimniok http://www.bot-thoughts.com/ + * + */ +#ifndef _SERIALGRAPHICLCD_H +#define _SERIALGRAPHICLCD_H + +#include "mbed.h" + +#define LCD_4800 1 +#define LCD_9600 2 +#define LCD_19200 3 +#define LCD_38400 4 +#define LCD_57600 5 +#define LCD_115200 6 + +/** Interface to the Sparkfun Serial Graphic LCD, LCD-09351; and Graphic + * LCD Serial Backpack, LCD-09352. Derived class from Serial so that you + * can conveniently printf(), putc(), etc to the display. + * + * Example: + * @code + * #include "mbed.h" + * #include "SerialGraphicLCD.h" + * + * SerialGraphicLCD lcd(p26, p25); + * + * int main() { + * lcd.baud(115200); // default baud rate + * while (1) { + * lcd.clear(); + * lcd.rect(3, 3, 20, 20); + * lcd.printf("Hello World!"); + * lcd.pixel(14, 35, true); + * lcd.pixel(16, 36, true); + * lcd.pixel(18, 37, true); + * lcd.pos(5, 30); + * lcd.printf("Hi"); + * lcd.circle(50, 20, 20, true); + * lcd.pos(50, 20); + * lcd.printf("Howdy"); + * lcd.line(0, 0, 25, 25, true); + * wait(2); + * } + * } + * @endcode + */ +class SerialGraphicLCD: public Serial { +public: + /** Create a new interface to a Serial Graphic LCD + */ + SerialGraphicLCD(PinName tx, PinName rx); + + /** clear the screen + */ + void clear(void); + + /** set text position + * + * @param x is the x coordinate + * @param y is the y coordinate + */ + void pos(int x, int y); + + /** set or erase a pixel + * + * @param x is the x coordinate + * @param y is the y coordinate + * @param set if true sets the pixel, if false, erases it + */ + void pixel(int x, int y, bool set); + + /** draw or erase a line + * + * @param x1 is the x coordinate of the start of the line + * @param y1 is the y coordinate of the start of the line + * @param x2 is the x coordinate of the end of the line + * @param y2 is the y coordinate of the end of the line + * @param set if true sets the line, if false, erases it + */ + void line(int x1, int y1, int x2, int y2, bool set); + + /** set or reset a circle + * + * @param x is the x coordinate of the circle center + * @param y is the y coordinate of the circle center + * @param r is the radius of the circle + * @param set if true sets the pixel, if false, clears it + */ + void circle(int x, int y, int r, bool set); + + /** draw or erase a rectangle + * + * @param x1 is the x coordinate of the upper left of the rectangle + * @param y1 is the y coordinate of the upper left of the rectangle + * @param x2 is the x coordinate of the lower right of the rectangle + * @param y2 is the y coordinate of the lower right of the rectangle + */ + void rect(int x1, int y1, int x2, int y2); + + /** erase a rectangular area + * + * @param x1 is the x coordinate of the upper left of the area + * @param y1 is the y coordinate of the upper left of the area + * @param x2 is the x coordinate of the lower right of the area + * @param y2 is the y coordinate of the lower right of the area + */ + void erase(int x1, int y1, int x2, int y2); + + /** set backlight duty cycle + * + * @param i is the duty cycle from 0 to 100; 0 is off, 100 is full power + */ + void backlight(int i); + + /** clear screen and put in reverse mode + */ + void reverseMode(void); + + /** configure the lcd baud rate so you have to call this along with baud() to change + * communication speeds + * + * @param b is the baud rate, LCD_4800, LCD_9600, LCD_19200, LCD_38400, LCD_57600 or LCD_115200 + */ + void lcdbaud(int b); +}; + + +#endif \ No newline at end of file