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.

Dependents:   DataBus2018

Committer:
shimniok
Date:
Wed Mar 28 16:04:25 2012 +0000
Revision:
0:a3d518d2f36f
Child:
1:2f436b8aebf4
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:a3d518d2f36f 1 /* Serial Graphics LCD Driver for Sparkfun Serial Graphics LCD, LCD-09351; and Graphic
shimniok 0:a3d518d2f36f 2 * LCD Serial Backpack, LCD-09352.
shimniok 0:a3d518d2f36f 3 *
shimniok 0:a3d518d2f36f 4 * @author Michael Shimniok http://www.bot-thoughts.com/
shimniok 0:a3d518d2f36f 5 *
shimniok 0:a3d518d2f36f 6 */
shimniok 0:a3d518d2f36f 7 #ifndef _SERIALGRAPHICLCD_H
shimniok 0:a3d518d2f36f 8 #define _SERIALGRAPHICLCD_H
shimniok 0:a3d518d2f36f 9
shimniok 0:a3d518d2f36f 10 #include "mbed.h"
shimniok 0:a3d518d2f36f 11
shimniok 0:a3d518d2f36f 12 #define LCD_4800 1
shimniok 0:a3d518d2f36f 13 #define LCD_9600 2
shimniok 0:a3d518d2f36f 14 #define LCD_19200 3
shimniok 0:a3d518d2f36f 15 #define LCD_38400 4
shimniok 0:a3d518d2f36f 16 #define LCD_57600 5
shimniok 0:a3d518d2f36f 17 #define LCD_115200 6
shimniok 0:a3d518d2f36f 18
shimniok 0:a3d518d2f36f 19 /** Interface to the Sparkfun Serial Graphic LCD, LCD-09351; and Graphic
shimniok 0:a3d518d2f36f 20 * LCD Serial Backpack, LCD-09352. Derived class from Serial so that you
shimniok 0:a3d518d2f36f 21 * can conveniently printf(), putc(), etc to the display.
shimniok 0:a3d518d2f36f 22 *
shimniok 0:a3d518d2f36f 23 * Example:
shimniok 0:a3d518d2f36f 24 * @code
shimniok 0:a3d518d2f36f 25 * #include "mbed.h"
shimniok 0:a3d518d2f36f 26 * #include "SerialGraphicLCD.h"
shimniok 0:a3d518d2f36f 27 *
shimniok 0:a3d518d2f36f 28 * SerialGraphicLCD lcd(p26, p25);
shimniok 0:a3d518d2f36f 29 *
shimniok 0:a3d518d2f36f 30 * int main() {
shimniok 0:a3d518d2f36f 31 * lcd.baud(115200); // default baud rate
shimniok 0:a3d518d2f36f 32 * while (1) {
shimniok 0:a3d518d2f36f 33 * lcd.clear();
shimniok 0:a3d518d2f36f 34 * lcd.rect(3, 3, 20, 20);
shimniok 0:a3d518d2f36f 35 * lcd.printf("Hello World!");
shimniok 0:a3d518d2f36f 36 * lcd.pixel(14, 35, true);
shimniok 0:a3d518d2f36f 37 * lcd.pixel(16, 36, true);
shimniok 0:a3d518d2f36f 38 * lcd.pixel(18, 37, true);
shimniok 0:a3d518d2f36f 39 * lcd.pos(5, 30);
shimniok 0:a3d518d2f36f 40 * lcd.printf("Hi");
shimniok 0:a3d518d2f36f 41 * lcd.circle(50, 20, 20, true);
shimniok 0:a3d518d2f36f 42 * lcd.pos(50, 20);
shimniok 0:a3d518d2f36f 43 * lcd.printf("Howdy");
shimniok 0:a3d518d2f36f 44 * lcd.line(0, 0, 25, 25, true);
shimniok 0:a3d518d2f36f 45 * wait(2);
shimniok 0:a3d518d2f36f 46 * }
shimniok 0:a3d518d2f36f 47 * }
shimniok 0:a3d518d2f36f 48 * @endcode
shimniok 0:a3d518d2f36f 49 */
shimniok 0:a3d518d2f36f 50 class SerialGraphicLCD: public Serial {
shimniok 0:a3d518d2f36f 51 public:
shimniok 0:a3d518d2f36f 52 /** Create a new interface to a Serial Graphic LCD
shimniok 0:a3d518d2f36f 53 */
shimniok 0:a3d518d2f36f 54 SerialGraphicLCD(PinName tx, PinName rx);
shimniok 0:a3d518d2f36f 55
shimniok 0:a3d518d2f36f 56 /** clear the screen
shimniok 0:a3d518d2f36f 57 */
shimniok 0:a3d518d2f36f 58 void clear(void);
shimniok 0:a3d518d2f36f 59
shimniok 0:a3d518d2f36f 60 /** set text position
shimniok 0:a3d518d2f36f 61 *
shimniok 0:a3d518d2f36f 62 * @param x is the x coordinate
shimniok 0:a3d518d2f36f 63 * @param y is the y coordinate
shimniok 0:a3d518d2f36f 64 */
shimniok 0:a3d518d2f36f 65 void pos(int x, int y);
shimniok 0:a3d518d2f36f 66
shimniok 0:a3d518d2f36f 67 /** set or erase a pixel
shimniok 0:a3d518d2f36f 68 *
shimniok 0:a3d518d2f36f 69 * @param x is the x coordinate
shimniok 0:a3d518d2f36f 70 * @param y is the y coordinate
shimniok 0:a3d518d2f36f 71 * @param set if true sets the pixel, if false, erases it
shimniok 0:a3d518d2f36f 72 */
shimniok 0:a3d518d2f36f 73 void pixel(int x, int y, bool set);
shimniok 0:a3d518d2f36f 74
shimniok 0:a3d518d2f36f 75 /** draw or erase a line
shimniok 0:a3d518d2f36f 76 *
shimniok 0:a3d518d2f36f 77 * @param x1 is the x coordinate of the start of the line
shimniok 0:a3d518d2f36f 78 * @param y1 is the y coordinate of the start of the line
shimniok 0:a3d518d2f36f 79 * @param x2 is the x coordinate of the end of the line
shimniok 0:a3d518d2f36f 80 * @param y2 is the y coordinate of the end of the line
shimniok 0:a3d518d2f36f 81 * @param set if true sets the line, if false, erases it
shimniok 0:a3d518d2f36f 82 */
shimniok 0:a3d518d2f36f 83 void line(int x1, int y1, int x2, int y2, bool set);
shimniok 0:a3d518d2f36f 84
shimniok 0:a3d518d2f36f 85 /** set or reset a circle
shimniok 0:a3d518d2f36f 86 *
shimniok 0:a3d518d2f36f 87 * @param x is the x coordinate of the circle center
shimniok 0:a3d518d2f36f 88 * @param y is the y coordinate of the circle center
shimniok 0:a3d518d2f36f 89 * @param r is the radius of the circle
shimniok 0:a3d518d2f36f 90 * @param set if true sets the pixel, if false, clears it
shimniok 0:a3d518d2f36f 91 */
shimniok 0:a3d518d2f36f 92 void circle(int x, int y, int r, bool set);
shimniok 0:a3d518d2f36f 93
shimniok 0:a3d518d2f36f 94 /** draw or erase a rectangle
shimniok 0:a3d518d2f36f 95 *
shimniok 0:a3d518d2f36f 96 * @param x1 is the x coordinate of the upper left of the rectangle
shimniok 0:a3d518d2f36f 97 * @param y1 is the y coordinate of the upper left of the rectangle
shimniok 0:a3d518d2f36f 98 * @param x2 is the x coordinate of the lower right of the rectangle
shimniok 0:a3d518d2f36f 99 * @param y2 is the y coordinate of the lower right of the rectangle
shimniok 0:a3d518d2f36f 100 */
shimniok 0:a3d518d2f36f 101 void rect(int x1, int y1, int x2, int y2);
shimniok 0:a3d518d2f36f 102
shimniok 0:a3d518d2f36f 103 /** erase a rectangular area
shimniok 0:a3d518d2f36f 104 *
shimniok 0:a3d518d2f36f 105 * @param x1 is the x coordinate of the upper left of the area
shimniok 0:a3d518d2f36f 106 * @param y1 is the y coordinate of the upper left of the area
shimniok 0:a3d518d2f36f 107 * @param x2 is the x coordinate of the lower right of the area
shimniok 0:a3d518d2f36f 108 * @param y2 is the y coordinate of the lower right of the area
shimniok 0:a3d518d2f36f 109 */
shimniok 0:a3d518d2f36f 110 void erase(int x1, int y1, int x2, int y2);
shimniok 0:a3d518d2f36f 111
shimniok 0:a3d518d2f36f 112 /** set backlight duty cycle
shimniok 0:a3d518d2f36f 113 *
shimniok 0:a3d518d2f36f 114 * @param i is the duty cycle from 0 to 100; 0 is off, 100 is full power
shimniok 0:a3d518d2f36f 115 */
shimniok 0:a3d518d2f36f 116 void backlight(int i);
shimniok 0:a3d518d2f36f 117
shimniok 0:a3d518d2f36f 118 /** clear screen and put in reverse mode
shimniok 0:a3d518d2f36f 119 */
shimniok 0:a3d518d2f36f 120 void reverseMode(void);
shimniok 0:a3d518d2f36f 121
shimniok 0:a3d518d2f36f 122 /** configure the lcd baud rate so you have to call this along with baud() to change
shimniok 0:a3d518d2f36f 123 * communication speeds
shimniok 0:a3d518d2f36f 124 *
shimniok 0:a3d518d2f36f 125 * @param b is the baud rate, LCD_4800, LCD_9600, LCD_19200, LCD_38400, LCD_57600 or LCD_115200
shimniok 0:a3d518d2f36f 126 */
shimniok 0:a3d518d2f36f 127 void lcdbaud(int b);
shimniok 0:a3d518d2f36f 128 };
shimniok 0:a3d518d2f36f 129
shimniok 0:a3d518d2f36f 130
shimniok 0:a3d518d2f36f 131 #endif