Code for autonomous ground vehicle, Data Bus, 3rd place winner in 2012 Sparkfun AVC.

Dependencies:   Watchdog mbed Schedule SimpleFilter LSM303DLM PinDetect DebounceIn Servo

Committer:
shimniok
Date:
Wed Jun 20 14:57:48 2012 +0000
Revision:
0:826c6171fc1b
Updated documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shimniok 0:826c6171fc1b 1 /* Serial Graphics LCD Driver for Sparkfun Serial Graphics LCD, LCD-09351; and Graphic
shimniok 0:826c6171fc1b 2 * LCD Serial Backpack, LCD-09352.
shimniok 0:826c6171fc1b 3 *
shimniok 0:826c6171fc1b 4 * @author Michael Shimniok http://www.bot-thoughts.com/
shimniok 0:826c6171fc1b 5 *
shimniok 0:826c6171fc1b 6 */
shimniok 0:826c6171fc1b 7 #ifndef _SERIALGRAPHICLCD_H
shimniok 0:826c6171fc1b 8 #define _SERIALGRAPHICLCD_H
shimniok 0:826c6171fc1b 9
shimniok 0:826c6171fc1b 10 #include "mbed.h"
shimniok 0:826c6171fc1b 11
shimniok 0:826c6171fc1b 12 /** Firmware modes */
shimniok 0:826c6171fc1b 13 #define SFE_FW 0 // Stock SFE firmware
shimniok 0:826c6171fc1b 14 #define SD_FW 1 // summoningdark firmware http://sourceforge.net/projects/serialglcd/
shimniok 0:826c6171fc1b 15
shimniok 0:826c6171fc1b 16 /** Modes for SD firmware */
shimniok 0:826c6171fc1b 17 #define FILL 0xFF
shimniok 0:826c6171fc1b 18 #define CLEAR 0x00
shimniok 0:826c6171fc1b 19
shimniok 0:826c6171fc1b 20 /** LCD Baud Rates */
shimniok 0:826c6171fc1b 21 #define LCD_4800 1
shimniok 0:826c6171fc1b 22 #define LCD_9600 2
shimniok 0:826c6171fc1b 23 #define LCD_19200 3
shimniok 0:826c6171fc1b 24 #define LCD_38400 4
shimniok 0:826c6171fc1b 25 #define LCD_57600 5
shimniok 0:826c6171fc1b 26 #define LCD_115200 6
shimniok 0:826c6171fc1b 27
shimniok 0:826c6171fc1b 28 /** LCD Types */
shimniok 0:826c6171fc1b 29 #define LCD_128x64 1
shimniok 0:826c6171fc1b 30 #define LCD_160x128 2
shimniok 0:826c6171fc1b 31
shimniok 0:826c6171fc1b 32 /** Interface to the Sparkfun Serial Graphic LCD, LCD-09351; and Graphic
shimniok 0:826c6171fc1b 33 * LCD Serial Backpack, LCD-09352. Derived class from Serial so that you
shimniok 0:826c6171fc1b 34 * can conveniently printf(), putc(), etc to the display.
shimniok 0:826c6171fc1b 35 *
shimniok 0:826c6171fc1b 36 * Example:
shimniok 0:826c6171fc1b 37 * @code
shimniok 0:826c6171fc1b 38 * #include "mbed.h"
shimniok 0:826c6171fc1b 39 * #include "SerialGraphicLCD.h"
shimniok 0:826c6171fc1b 40 *
shimniok 0:826c6171fc1b 41 * SerialGraphicLCD lcd(p26, p25);
shimniok 0:826c6171fc1b 42 *
shimniok 0:826c6171fc1b 43 * int main() {
shimniok 0:826c6171fc1b 44 * lcd.baud(115200); // default baud rate
shimniok 0:826c6171fc1b 45 * while (1) {
shimniok 0:826c6171fc1b 46 * lcd.clear();
shimniok 0:826c6171fc1b 47 * lcd.rect(3, 3, 20, 20);
shimniok 0:826c6171fc1b 48 * lcd.printf("Hello World!");
shimniok 0:826c6171fc1b 49 * lcd.pixel(14, 35, true);
shimniok 0:826c6171fc1b 50 * lcd.pixel(16, 36, true);
shimniok 0:826c6171fc1b 51 * lcd.pixel(18, 37, true);
shimniok 0:826c6171fc1b 52 * lcd.pos(5, 30);
shimniok 0:826c6171fc1b 53 * lcd.printf("Hi");
shimniok 0:826c6171fc1b 54 * lcd.circle(50, 20, 20, true);
shimniok 0:826c6171fc1b 55 * lcd.pos(50, 20);
shimniok 0:826c6171fc1b 56 * lcd.printf("Howdy");
shimniok 0:826c6171fc1b 57 * lcd.line(0, 0, 25, 25, true);
shimniok 0:826c6171fc1b 58 * wait(2);
shimniok 0:826c6171fc1b 59 * }
shimniok 0:826c6171fc1b 60 * }
shimniok 0:826c6171fc1b 61 * @endcode
shimniok 0:826c6171fc1b 62 */
shimniok 0:826c6171fc1b 63 class SerialGraphicLCD: public Serial {
shimniok 0:826c6171fc1b 64 public:
shimniok 0:826c6171fc1b 65 /** Create a new interface to a Serial Graphic LCD
shimniok 0:826c6171fc1b 66 * Note that the display lower left corner is coordinates 0, 0.
shimniok 0:826c6171fc1b 67 * Rows start at the top at 0, columns start at the left at 0.
shimniok 0:826c6171fc1b 68 * @param tx -- mbed transmit pin
shimniok 0:826c6171fc1b 69 * @param rx -- mbed receive pin
shimniok 0:826c6171fc1b 70 */
shimniok 0:826c6171fc1b 71 SerialGraphicLCD(PinName tx, PinName rx);
shimniok 0:826c6171fc1b 72
shimniok 0:826c6171fc1b 73 /** Create a new interface to a Serial Graphic LCD
shimniok 0:826c6171fc1b 74 * Note that the display lower left corner is coordinates 0, 0.
shimniok 0:826c6171fc1b 75 * Rows start at the top at 0, columns start at the left at 0.
shimniok 0:826c6171fc1b 76 * @param tx -- mbed transmit pin
shimniok 0:826c6171fc1b 77 * @param rx -- mbed receive pin
shimniok 0:826c6171fc1b 78 * @param firmware -- SFE_FW, stock firmware or SD_FW, summoningdark firmware
shimniok 0:826c6171fc1b 79 */
shimniok 0:826c6171fc1b 80 SerialGraphicLCD(PinName tx, PinName rx, int firmware);
shimniok 0:826c6171fc1b 81
shimniok 0:826c6171fc1b 82 /** clear the screen
shimniok 0:826c6171fc1b 83 */
shimniok 0:826c6171fc1b 84 void clear(void);
shimniok 0:826c6171fc1b 85
shimniok 0:826c6171fc1b 86 /** set text position in rows, columns
shimniok 0:826c6171fc1b 87 *
shimniok 0:826c6171fc1b 88 * @param col is the col coordinate
shimniok 0:826c6171fc1b 89 * @param row is the row coordinate
shimniok 0:826c6171fc1b 90 */
shimniok 0:826c6171fc1b 91 void pos(int col, int row);
shimniok 0:826c6171fc1b 92
shimniok 0:826c6171fc1b 93 /** set text position in x, y coordinates
shimniok 0:826c6171fc1b 94 *
shimniok 0:826c6171fc1b 95 * @param x is the x coordinate
shimniok 0:826c6171fc1b 96 * @param y is the y coordinate
shimniok 0:826c6171fc1b 97 */
shimniok 0:826c6171fc1b 98 void posXY(int x, int y);
shimniok 0:826c6171fc1b 99
shimniok 0:826c6171fc1b 100 /** set or erase a pixel
shimniok 0:826c6171fc1b 101 *
shimniok 0:826c6171fc1b 102 * @param x is the x coordinate
shimniok 0:826c6171fc1b 103 * @param y is the y coordinate
shimniok 0:826c6171fc1b 104 * @param set if true sets the pixel, if false, erases it
shimniok 0:826c6171fc1b 105 */
shimniok 0:826c6171fc1b 106 void pixel(int x, int y, bool set);
shimniok 0:826c6171fc1b 107
shimniok 0:826c6171fc1b 108 /** draw or erase a line
shimniok 0:826c6171fc1b 109 *
shimniok 0:826c6171fc1b 110 * @param x1 is the x coordinate of the start of the line
shimniok 0:826c6171fc1b 111 * @param y1 is the y coordinate of the start of the line
shimniok 0:826c6171fc1b 112 * @param x2 is the x coordinate of the end of the line
shimniok 0:826c6171fc1b 113 * @param y2 is the y coordinate of the end of the line
shimniok 0:826c6171fc1b 114 * @param set if true sets the line, if false, erases it
shimniok 0:826c6171fc1b 115 */
shimniok 0:826c6171fc1b 116 void line(int x1, int y1, int x2, int y2, bool set);
shimniok 0:826c6171fc1b 117
shimniok 0:826c6171fc1b 118 /** set or reset a circle
shimniok 0:826c6171fc1b 119 *
shimniok 0:826c6171fc1b 120 * @param x is the x coordinate of the circle center
shimniok 0:826c6171fc1b 121 * @param y is the y coordinate of the circle center
shimniok 0:826c6171fc1b 122 * @param r is the radius of the circle
shimniok 0:826c6171fc1b 123 * @param set if true sets the pixel, if false, clears it
shimniok 0:826c6171fc1b 124 */
shimniok 0:826c6171fc1b 125 void circle(int x, int y, int r, bool set);
shimniok 0:826c6171fc1b 126
shimniok 0:826c6171fc1b 127 /** draw a rectangle
shimniok 0:826c6171fc1b 128 *
shimniok 0:826c6171fc1b 129 * @param x1 is the x coordinate of the upper left of the rectangle
shimniok 0:826c6171fc1b 130 * @param y1 is the y coordinate of the upper left of the rectangle
shimniok 0:826c6171fc1b 131 * @param x2 is the x coordinate of the lower right of the rectangle
shimniok 0:826c6171fc1b 132 * @param y2 is the y coordinate of the lower right of the rectangle
shimniok 0:826c6171fc1b 133 */
shimniok 0:826c6171fc1b 134 void rect(int x1, int y1, int x2, int y2);
shimniok 0:826c6171fc1b 135
shimniok 0:826c6171fc1b 136 /** draw or erase a rectangle (SD firmware only)
shimniok 0:826c6171fc1b 137 *
shimniok 0:826c6171fc1b 138 * @param x1 is the x coordinate of the upper left of the rectangle
shimniok 0:826c6171fc1b 139 * @param y1 is the y coordinate of the upper left of the rectangle
shimniok 0:826c6171fc1b 140 * @param x2 is the x coordinate of the lower right of the rectangle
shimniok 0:826c6171fc1b 141 * @param y2 is the y coordinate of the lower right of the rectangle
shimniok 0:826c6171fc1b 142 */
shimniok 0:826c6171fc1b 143 void rect(int x1, int y1, int x2, int y2, bool set);
shimniok 0:826c6171fc1b 144
shimniok 0:826c6171fc1b 145 /** Draw a filled box.
shimniok 0:826c6171fc1b 146 *
shimniok 0:826c6171fc1b 147 * @param x1 is the x coordinate of the upper left of the rectangle
shimniok 0:826c6171fc1b 148 * @param y1 is the y coordinate of the upper left of the rectangle
shimniok 0:826c6171fc1b 149 * @param x2 is the x coordinate of the lower right of the rectangle
shimniok 0:826c6171fc1b 150 * @param y2 is the y coordinate of the lower right of the rectangle
shimniok 0:826c6171fc1b 151 * @param fillByte describes 1 8-pixel high stripe that is repeated every x
shimniok 0:826c6171fc1b 152 * pixels and every 8 y pixels. The most useful are CLEAR (0x00) to clear the box, and FILL (0xFF) to fill it.
shimniok 0:826c6171fc1b 153 */
shimniok 0:826c6171fc1b 154 void rectFill(int x1, int y1, int x2, int y2, char fillByte);
shimniok 0:826c6171fc1b 155
shimniok 0:826c6171fc1b 156 /** erase a rectangular area
shimniok 0:826c6171fc1b 157 *
shimniok 0:826c6171fc1b 158 * @param x1 is the x coordinate of the upper left of the area
shimniok 0:826c6171fc1b 159 * @param y1 is the y coordinate of the upper left of the area
shimniok 0:826c6171fc1b 160 * @param x2 is the x coordinate of the lower right of the area
shimniok 0:826c6171fc1b 161 * @param y2 is the y coordinate of the lower right of the area
shimniok 0:826c6171fc1b 162 */
shimniok 0:826c6171fc1b 163 void erase(int x1, int y1, int x2, int y2);
shimniok 0:826c6171fc1b 164
shimniok 0:826c6171fc1b 165 /** set backlight duty cycle
shimniok 0:826c6171fc1b 166 *
shimniok 0:826c6171fc1b 167 * @param i is the duty cycle from 0 to 100; 0 is off, 100 is full power
shimniok 0:826c6171fc1b 168 */
shimniok 0:826c6171fc1b 169 void backlight(int i);
shimniok 0:826c6171fc1b 170
shimniok 0:826c6171fc1b 171 /** clear screen and put in reverse mode
shimniok 0:826c6171fc1b 172 */
shimniok 0:826c6171fc1b 173 void reverseMode(void);
shimniok 0:826c6171fc1b 174
shimniok 0:826c6171fc1b 175 /** configure the lcd baud rate so you have to call this along with baud() to change
shimniok 0:826c6171fc1b 176 * communication speeds
shimniok 0:826c6171fc1b 177 *
shimniok 0:826c6171fc1b 178 * @param b is the baud rate, LCD_4800, LCD_9600, LCD_19200, LCD_38400, LCD_57600 or LCD_115200
shimniok 0:826c6171fc1b 179 */
shimniok 0:826c6171fc1b 180 void lcdbaud(int b);
shimniok 0:826c6171fc1b 181
shimniok 0:826c6171fc1b 182
shimniok 0:826c6171fc1b 183 /** sets the resolution of the LCD so that the pos() call works properly
shimniok 0:826c6171fc1b 184 * defaults to LCD_128x64.
shimniok 0:826c6171fc1b 185 *
shimniok 0:826c6171fc1b 186 * @param type is the type of LCD, either LCD_128x64 or LCD_160x128
shimniok 0:826c6171fc1b 187 */
shimniok 0:826c6171fc1b 188 void resolution(int type);
shimniok 0:826c6171fc1b 189
shimniok 0:826c6171fc1b 190 /** sets the resolution of the LCD in x and y coordinates which determines
shimniok 0:826c6171fc1b 191 * how rows and columns are calculated in the pos() call. Defaults to
shimniok 0:826c6171fc1b 192 * x=128, y=64
shimniok 0:826c6171fc1b 193 *
shimniok 0:826c6171fc1b 194 * @param x is the number of horizontal pixels
shimniok 0:826c6171fc1b 195 * @param y is the number of vertical pixels
shimniok 0:826c6171fc1b 196 */
shimniok 0:826c6171fc1b 197 void resolution(int x, int y);
shimniok 0:826c6171fc1b 198
shimniok 0:826c6171fc1b 199 private:
shimniok 0:826c6171fc1b 200 int _xMax;
shimniok 0:826c6171fc1b 201 int _yMax;
shimniok 0:826c6171fc1b 202 int _firmware;
shimniok 0:826c6171fc1b 203 };
shimniok 0:826c6171fc1b 204
shimniok 0:826c6171fc1b 205
shimniok 0:826c6171fc1b 206 #endif