Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.

Dependencies:   mbed Watchdog SDFileSystem DigoleSerialDisp

Committer:
shimniok
Date:
Fri Nov 30 16:11:53 2018 +0000
Revision:
25:bb5356402687
Parent:
0:a6a169de725f
Initial publish of revised version.

Who changed what in which revision?

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