First Draft, serial print change based on distance

Committer:
liam94
Date:
Sat Dec 04 17:15:09 2021 +0000
Revision:
0:506531d0531c
1st Draft

Who changed what in which revision?

UserRevisionLine numberNew contents of line
liam94 0:506531d0531c 1 #ifndef N5110_H
liam94 0:506531d0531c 2 #define N5110_H
liam94 0:506531d0531c 3
liam94 0:506531d0531c 4 #include "mbed.h"
liam94 0:506531d0531c 5
liam94 0:506531d0531c 6 // number of pixels on display
liam94 0:506531d0531c 7 #define WIDTH 84
liam94 0:506531d0531c 8 #define HEIGHT 48
liam94 0:506531d0531c 9 #define BANKS 6
liam94 0:506531d0531c 10
liam94 0:506531d0531c 11 /// Fill types for 2D shapes
liam94 0:506531d0531c 12 enum FillType {
liam94 0:506531d0531c 13 FILL_TRANSPARENT, ///< Transparent with outline
liam94 0:506531d0531c 14 FILL_BLACK, ///< Filled black
liam94 0:506531d0531c 15 FILL_WHITE, ///< Filled white (no outline)
liam94 0:506531d0531c 16 };
liam94 0:506531d0531c 17
liam94 0:506531d0531c 18 /** N5110 Class
liam94 0:506531d0531c 19 @brief Library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168) using the hardware SPI on the mbed.
liam94 0:506531d0531c 20 @brief The display is powered from a GPIO pin meaning it can be controlled via software. The LED backlight is also software-controllable (via PWM pin).
liam94 0:506531d0531c 21 @brief Can print characters and strings to the display using the included 5x7 font.
liam94 0:506531d0531c 22 @brief The library also implements a screen buffer so that individual pixels on the display (84 x 48) can be set, cleared and read.
liam94 0:506531d0531c 23 @brief The library can print primitive shapes (lines, circles, rectangles)
liam94 0:506531d0531c 24 @brief Acknowledgements to Chris Yan's Nokia_5110 Library.
liam94 0:506531d0531c 25
liam94 0:506531d0531c 26 @brief Revision 1.4
liam94 0:506531d0531c 27
liam94 0:506531d0531c 28 @upgraded Dr. Edmond Nurellari
liam94 0:506531d0531c 29 @date 1st December 2021
liam94 0:506531d0531c 30
liam94 0:506531d0531c 31 @code
liam94 0:506531d0531c 32
liam94 0:506531d0531c 33 #include "mbed.h"
liam94 0:506531d0531c 34 #include "N5110.h"
liam94 0:506531d0531c 35
liam94 0:506531d0531c 36 // rows,cols
liam94 0:506531d0531c 37 int sprite[8][5] = {
liam94 0:506531d0531c 38 { 0,0,1,0,0 },
liam94 0:506531d0531c 39 { 0,1,1,1,0 },
liam94 0:506531d0531c 40 { 0,0,1,0,0 },
liam94 0:506531d0531c 41 { 0,1,1,1,0 },
liam94 0:506531d0531c 42 { 1,1,1,1,1 },
liam94 0:506531d0531c 43 { 1,1,1,1,1 },
liam94 0:506531d0531c 44 { 1,1,0,1,1 },
liam94 0:506531d0531c 45 { 1,1,0,1,1 },
liam94 0:506531d0531c 46 };
liam94 0:506531d0531c 47
liam94 0:506531d0531c 48 // VCC,SCE,RST,D/C,MOSI,SCLK,LED
liam94 0:506531d0531c 49 //N5110 lcd(p7,p8,p9,p10,p11,p13,p21); // LPC1768 - pwr from GPIO
liam94 0:506531d0531c 50 N5110 lcd(p8,p9,p10,p11,p13,p21); // LPC1768 - powered from +3V3 - JP1 in 2/3 position
liam94 0:506531d0531c 51 //N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // K64F - pwr from 3V3
liam94 0:506531d0531c 52
liam94 0:506531d0531c 53 int main()
liam94 0:506531d0531c 54 {
liam94 0:506531d0531c 55 // first need to initialise display
liam94 0:506531d0531c 56 lcd.init();
liam94 0:506531d0531c 57
liam94 0:506531d0531c 58 // change set contrast in range 0.0 to 1.0
liam94 0:506531d0531c 59 // 0.4 appears to be a good starting point
liam94 0:506531d0531c 60 lcd.setContrast(0.4);
liam94 0:506531d0531c 61
liam94 0:506531d0531c 62 while(1) {
liam94 0:506531d0531c 63
liam94 0:506531d0531c 64 // these are default settings so not strictly needed
liam94 0:506531d0531c 65 lcd.normalMode(); // normal colour mode
liam94 0:506531d0531c 66 lcd.setBrightness(0.5); // put LED backlight on 50%
liam94 0:506531d0531c 67
liam94 0:506531d0531c 68 lcd.clear();
liam94 0:506531d0531c 69 // x origin, y origin, rows, cols, sprite
liam94 0:506531d0531c 70 lcd.drawSprite(20,6,8,5,(int *)sprite);
liam94 0:506531d0531c 71 lcd.refresh();
liam94 0:506531d0531c 72 wait(5.0);
liam94 0:506531d0531c 73
liam94 0:506531d0531c 74 lcd.clear(); // clear buffer at start of every loop
liam94 0:506531d0531c 75 // can directly print strings at specified co-ordinates (must be less than 84 pixels to fit on display)
liam94 0:506531d0531c 76 lcd.printString("Hello, World!",0,0);
liam94 0:506531d0531c 77
liam94 0:506531d0531c 78 char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14)
liam94 0:506531d0531c 79 // so can display a string of a maximum 14 characters in length
liam94 0:506531d0531c 80 // or create formatted strings - ensure they aren't more than 14 characters long
liam94 0:506531d0531c 81 int temperature = 27;
liam94 0:506531d0531c 82 int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer
liam94 0:506531d0531c 83 // it is important the format specifier ensures the length will fit in the buffer
liam94 0:506531d0531c 84 if (length <= 14) // if string will fit on display (assuming printing at x=0)
liam94 0:506531d0531c 85 lcd.printString(buffer,0,1); // display on screen
liam94 0:506531d0531c 86
liam94 0:506531d0531c 87 float pressure = 1012.3; // same idea with floats
liam94 0:506531d0531c 88 length = sprintf(buffer,"P = %.2f mb",pressure);
liam94 0:506531d0531c 89 if (length <= 14)
liam94 0:506531d0531c 90 lcd.printString(buffer,0,2);
liam94 0:506531d0531c 91
liam94 0:506531d0531c 92 // can also print individual characters at specified place
liam94 0:506531d0531c 93 lcd.printChar('X',5,3);
liam94 0:506531d0531c 94
liam94 0:506531d0531c 95 // draw a line across the display at y = 40 pixels (origin top-left)
liam94 0:506531d0531c 96 for (int i = 0; i < WIDTH; i++) {
liam94 0:506531d0531c 97 lcd.setPixel(i,40,true);
liam94 0:506531d0531c 98 }
liam94 0:506531d0531c 99 // need to refresh display after setting pixels or writing strings
liam94 0:506531d0531c 100 lcd.refresh();
liam94 0:506531d0531c 101 wait(5.0);
liam94 0:506531d0531c 102
liam94 0:506531d0531c 103 // can check status of pixel using getPixel(x,y);
liam94 0:506531d0531c 104 lcd.clear(); // clear buffer
liam94 0:506531d0531c 105 lcd.setPixel(2,2,true); // set random pixel in buffer
liam94 0:506531d0531c 106 lcd.refresh();
liam94 0:506531d0531c 107 wait(1.0);
liam94 0:506531d0531c 108
liam94 0:506531d0531c 109 int pixel_to_test = lcd.getPixel(2,2);
liam94 0:506531d0531c 110
liam94 0:506531d0531c 111 if ( pixel_to_test ) {
liam94 0:506531d0531c 112 lcd.printString("2,2 is set",0,4);
liam94 0:506531d0531c 113 }
liam94 0:506531d0531c 114
liam94 0:506531d0531c 115 // this one shouldn't be set
liam94 0:506531d0531c 116 lcd.setPixel(3,3,false); // clear random pixel in buffer
liam94 0:506531d0531c 117 lcd.refresh();
liam94 0:506531d0531c 118 pixel_to_test = lcd.getPixel(3,3);
liam94 0:506531d0531c 119
liam94 0:506531d0531c 120 if ( pixel_to_test == 0 ) {
liam94 0:506531d0531c 121 lcd.printString("3,3 is clear",0,5);
liam94 0:506531d0531c 122 }
liam94 0:506531d0531c 123
liam94 0:506531d0531c 124 lcd.refresh();
liam94 0:506531d0531c 125 wait(4.0);
liam94 0:506531d0531c 126
liam94 0:506531d0531c 127 lcd.clear(); // clear buffer
liam94 0:506531d0531c 128 lcd.inverseMode(); // invert colours
liam94 0:506531d0531c 129 lcd.setBrightness(1.0); // put LED backlight on full
liam94 0:506531d0531c 130
liam94 0:506531d0531c 131 float array[84];
liam94 0:506531d0531c 132
liam94 0:506531d0531c 133 for (int i = 0; i < 84; i++) {
liam94 0:506531d0531c 134 array[i] = 0.5 + 0.5*sin(i*2*3.14/84);
liam94 0:506531d0531c 135 }
liam94 0:506531d0531c 136
liam94 0:506531d0531c 137 // can also plot graphs - 84 elements only
liam94 0:506531d0531c 138 // values must be in range 0.0 - 1.0
liam94 0:506531d0531c 139 lcd.plotArray(array);
liam94 0:506531d0531c 140 lcd.refresh();
liam94 0:506531d0531c 141 wait(5.0);
liam94 0:506531d0531c 142
liam94 0:506531d0531c 143 lcd.clear();
liam94 0:506531d0531c 144 lcd.normalMode(); // normal colour mode back
liam94 0:506531d0531c 145 lcd.setBrightness(0.5); // put LED backlight on 50%
liam94 0:506531d0531c 146
liam94 0:506531d0531c 147 // example of drawing lines
liam94 0:506531d0531c 148 for (int x = 0; x < WIDTH ; x+=10) {
liam94 0:506531d0531c 149 // x0,y0,x1,y1,type 0-white,1-black,2-dotted
liam94 0:506531d0531c 150 lcd.drawLine(0,0,x,HEIGHT,2);
liam94 0:506531d0531c 151 }
liam94 0:506531d0531c 152 lcd.refresh(); // refresh after drawing shapes
liam94 0:506531d0531c 153 wait(5.0);
liam94 0:506531d0531c 154
liam94 0:506531d0531c 155
liam94 0:506531d0531c 156 lcd.clear();
liam94 0:506531d0531c 157 // example of how to draw circles
liam94 0:506531d0531c 158 lcd.drawCircle(WIDTH/2,HEIGHT/2,20,FILL_BLACK); // x,y,radius,black fill
liam94 0:506531d0531c 159 lcd.drawCircle(WIDTH/2,HEIGHT/2,10,FILL_WHITE); // x,y,radius,white fill
liam94 0:506531d0531c 160 lcd.drawCircle(WIDTH/2,HEIGHT/2,30,FILL_TRANSPARENT); // x,y,radius,transparent with outline
liam94 0:506531d0531c 161 lcd.refresh(); // refresh after drawing shapes
liam94 0:506531d0531c 162 wait(5.0);
liam94 0:506531d0531c 163
liam94 0:506531d0531c 164 lcd.clear();
liam94 0:506531d0531c 165 // example of how to draw rectangles
liam94 0:506531d0531c 166 // origin x,y,width,height,type
liam94 0:506531d0531c 167 lcd.drawRect(10,10,50,30,FILL_BLACK); // filled black rectangle
liam94 0:506531d0531c 168 lcd.drawRect(15,15,20,10,FILL_WHITE); // filled white rectange (no outline)
liam94 0:506531d0531c 169 lcd.drawRect(2,2,70,40,FILL_TRANSPARENT); // transparent, just outline
liam94 0:506531d0531c 170 lcd.refresh(); // refresh after drawing shapes
liam94 0:506531d0531c 171 wait(5.0);
liam94 0:506531d0531c 172
liam94 0:506531d0531c 173 }
liam94 0:506531d0531c 174 }
liam94 0:506531d0531c 175
liam94 0:506531d0531c 176
liam94 0:506531d0531c 177 @endcode
liam94 0:506531d0531c 178 */
liam94 0:506531d0531c 179 class N5110
liam94 0:506531d0531c 180 {
liam94 0:506531d0531c 181 private:
liam94 0:506531d0531c 182 // objects
liam94 0:506531d0531c 183 SPI *_spi;
liam94 0:506531d0531c 184 PwmOut *_led;
liam94 0:506531d0531c 185 DigitalOut *_pwr;
liam94 0:506531d0531c 186 DigitalOut *_sce;
liam94 0:506531d0531c 187 DigitalOut *_rst;
liam94 0:506531d0531c 188 DigitalOut *_dc;
liam94 0:506531d0531c 189
liam94 0:506531d0531c 190 // variables
liam94 0:506531d0531c 191 unsigned char buffer[84][6]; // screen buffer - the 6 is for the banks - each one is 8 bits;
liam94 0:506531d0531c 192
liam94 0:506531d0531c 193 public:
liam94 0:506531d0531c 194 /** Create a N5110 object connected to the specified pins
liam94 0:506531d0531c 195 *
liam94 0:506531d0531c 196 * @param pwr Pin connected to Vcc on the LCD display (pin 1)
liam94 0:506531d0531c 197 * @param sce Pin connected to chip enable (pin 3)
liam94 0:506531d0531c 198 * @param rst Pin connected to reset (pin 4)
liam94 0:506531d0531c 199 * @param dc Pin connected to data/command select (pin 5)
liam94 0:506531d0531c 200 * @param mosi Pin connected to data input (MOSI) (pin 6)
liam94 0:506531d0531c 201 * @param sclk Pin connected to serial clock (SCLK) (pin 7)
liam94 0:506531d0531c 202 * @param led Pin connected to LED backlight (must be PWM) (pin 8)
liam94 0:506531d0531c 203 *
liam94 0:506531d0531c 204 */
liam94 0:506531d0531c 205 N5110(PinName const pwrPin,
liam94 0:506531d0531c 206 PinName const scePin,
liam94 0:506531d0531c 207 PinName const rstPin,
liam94 0:506531d0531c 208 PinName const dcPin,
liam94 0:506531d0531c 209 PinName const mosiPin,
liam94 0:506531d0531c 210 PinName const sclkPin,
liam94 0:506531d0531c 211 PinName const ledPin);
liam94 0:506531d0531c 212
liam94 0:506531d0531c 213 /** Create a N5110 object connected to the specified pins (Vcc to +3V3)
liam94 0:506531d0531c 214 *
liam94 0:506531d0531c 215 * @param sce Pin connected to chip enable (pin 3)
liam94 0:506531d0531c 216 * @param rst Pin connected to reset (pin 4)
liam94 0:506531d0531c 217 * @param dc Pin connected to data/command select (pin 5)
liam94 0:506531d0531c 218 * @param mosi Pin connected to data input (MOSI) (pin 6)
liam94 0:506531d0531c 219 * @param sclk Pin connected to serial clock (SCLK) (pin 7)
liam94 0:506531d0531c 220 * @param led Pin connected to LED backlight (must be PWM) (pin 8)
liam94 0:506531d0531c 221 *
liam94 0:506531d0531c 222 */
liam94 0:506531d0531c 223 N5110(PinName const scePin,
liam94 0:506531d0531c 224 PinName const rstPin,
liam94 0:506531d0531c 225 PinName const dcPin,
liam94 0:506531d0531c 226 PinName const mosiPin,
liam94 0:506531d0531c 227 PinName const sclkPin,
liam94 0:506531d0531c 228 PinName const ledPin);
liam94 0:506531d0531c 229
liam94 0:506531d0531c 230 /**
liam94 0:506531d0531c 231 * Free allocated memory when object goes out of scope
liam94 0:506531d0531c 232 */
liam94 0:506531d0531c 233 ~N5110();
liam94 0:506531d0531c 234
liam94 0:506531d0531c 235 /** Initialise display
liam94 0:506531d0531c 236 *
liam94 0:506531d0531c 237 * Powers up the display and turns on backlight (50% brightness default).
liam94 0:506531d0531c 238 * Sets the display up in horizontal addressing mode and with normal video mode.
liam94 0:506531d0531c 239 */
liam94 0:506531d0531c 240 void init();
liam94 0:506531d0531c 241
liam94 0:506531d0531c 242 /** Turn off
liam94 0:506531d0531c 243 *
liam94 0:506531d0531c 244 * Powers down the display and turns of the backlight.
liam94 0:506531d0531c 245 * Needs to be reinitialised before being re-used.
liam94 0:506531d0531c 246 */
liam94 0:506531d0531c 247 void turnOff();
liam94 0:506531d0531c 248
liam94 0:506531d0531c 249 /** Clear
liam94 0:506531d0531c 250 *
liam94 0:506531d0531c 251 * Clears the screen buffer.
liam94 0:506531d0531c 252 */
liam94 0:506531d0531c 253 void clear();
liam94 0:506531d0531c 254
liam94 0:506531d0531c 255 /** Set screen constrast
liam94 0:506531d0531c 256 * @param constrast - float in range 0.0 to 1.0 (0.40 to 0.60 is usually a good value)
liam94 0:506531d0531c 257 */
liam94 0:506531d0531c 258 void setContrast(float contrast);
liam94 0:506531d0531c 259
liam94 0:506531d0531c 260 /** Turn on normal video mode (default)
liam94 0:506531d0531c 261 * Black on white
liam94 0:506531d0531c 262 */
liam94 0:506531d0531c 263 void normalMode();
liam94 0:506531d0531c 264
liam94 0:506531d0531c 265 /** Turn on inverse video mode (default)
liam94 0:506531d0531c 266 * White on black
liam94 0:506531d0531c 267 */
liam94 0:506531d0531c 268 void inverseMode();
liam94 0:506531d0531c 269
liam94 0:506531d0531c 270 /** Set Brightness
liam94 0:506531d0531c 271 *
liam94 0:506531d0531c 272 * Sets brightness of LED backlight.
liam94 0:506531d0531c 273 * @param brightness - float in range 0.0 to 1.0
liam94 0:506531d0531c 274 */
liam94 0:506531d0531c 275 void setBrightness(float const brightness);
liam94 0:506531d0531c 276
liam94 0:506531d0531c 277 /** Print String
liam94 0:506531d0531c 278 *
liam94 0:506531d0531c 279 * Prints a string of characters to the screen buffer. String is cut-off after the 83rd pixel.
liam94 0:506531d0531c 280 * @param x - the column number (0 to 83)
liam94 0:506531d0531c 281 * @param y - the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row
liam94 0:506531d0531c 282 */
liam94 0:506531d0531c 283 void printString(char const *str,
liam94 0:506531d0531c 284 unsigned int const x,
liam94 0:506531d0531c 285 unsigned int const y);
liam94 0:506531d0531c 286
liam94 0:506531d0531c 287 /** Print Character
liam94 0:506531d0531c 288 *
liam94 0:506531d0531c 289 * Sends a character to the screen buffer. Printed at the specified location. Character is cut-off after the 83rd pixel.
liam94 0:506531d0531c 290 * @param c - the character to print. Can print ASCII as so printChar('C').
liam94 0:506531d0531c 291 * @param x - the column number (0 to 83)
liam94 0:506531d0531c 292 * @param y - the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row
liam94 0:506531d0531c 293 */
liam94 0:506531d0531c 294 void printChar(char const c,
liam94 0:506531d0531c 295 unsigned int const x,
liam94 0:506531d0531c 296 unsigned int const y);
liam94 0:506531d0531c 297
liam94 0:506531d0531c 298 /**
liam94 0:506531d0531c 299 * @brief Set a Pixel
liam94 0:506531d0531c 300 *
liam94 0:506531d0531c 301 * @param x The x co-ordinate of the pixel (0 to 83)
liam94 0:506531d0531c 302 * @param y The y co-ordinate of the pixel (0 to 47)
liam94 0:506531d0531c 303 * @param state The state of the pixel [true=black (default), false=white]
liam94 0:506531d0531c 304 *
liam94 0:506531d0531c 305 * @details This function sets the state of a pixel in the screen buffer.
liam94 0:506531d0531c 306 * The third parameter can be omitted,
liam94 0:506531d0531c 307 */
liam94 0:506531d0531c 308 void setPixel(unsigned int const x,
liam94 0:506531d0531c 309 unsigned int const y,
liam94 0:506531d0531c 310 bool const state = true);
liam94 0:506531d0531c 311
liam94 0:506531d0531c 312 /**
liam94 0:506531d0531c 313 * @brief Clear a Pixel
liam94 0:506531d0531c 314 *
liam94 0:506531d0531c 315 * @param x - the x co-ordinate of the pixel (0 to 83)
liam94 0:506531d0531c 316 * @param y - the y co-ordinate of the pixel (0 to 47)
liam94 0:506531d0531c 317 *
liam94 0:506531d0531c 318 * @details This function clears pixel in the screen buffer
liam94 0:506531d0531c 319 *
liam94 0:506531d0531c 320 * @deprecated Use setPixel(x, y, false) instead
liam94 0:506531d0531c 321 */
liam94 0:506531d0531c 322 void clearPixel(unsigned int const x,
liam94 0:506531d0531c 323 unsigned int const y)
liam94 0:506531d0531c 324 __attribute__((deprecated("Use setPixel(x,y,false) instead")));
liam94 0:506531d0531c 325
liam94 0:506531d0531c 326 /** Get a Pixel
liam94 0:506531d0531c 327 *
liam94 0:506531d0531c 328 * This function gets the status of a pixel in the screen buffer.
liam94 0:506531d0531c 329 * @param x - the x co-ordinate of the pixel (0 to 83)
liam94 0:506531d0531c 330 * @param y - the y co-ordinate of the pixel (0 to 47)
liam94 0:506531d0531c 331 * @returns
liam94 0:506531d0531c 332 * 0 - pixel is clear
liam94 0:506531d0531c 333 * 1 - pixel is set
liam94 0:506531d0531c 334 */
liam94 0:506531d0531c 335 int getPixel(unsigned int const x,
liam94 0:506531d0531c 336 unsigned int const y) const;
liam94 0:506531d0531c 337
liam94 0:506531d0531c 338 /** Refresh display
liam94 0:506531d0531c 339 *
liam94 0:506531d0531c 340 * This functions sends the screen buffer to the display.
liam94 0:506531d0531c 341 */
liam94 0:506531d0531c 342 void refresh();
liam94 0:506531d0531c 343
liam94 0:506531d0531c 344 /** Randomise buffer
liam94 0:506531d0531c 345 *
liam94 0:506531d0531c 346 * This function fills the buffer with random data. Can be used to test the display.
liam94 0:506531d0531c 347 * A call to refresh() must be made to update the display to reflect the change in pixels.
liam94 0:506531d0531c 348 * The seed is not set and so the generated pattern will probably be the same each time.
liam94 0:506531d0531c 349 * TODO: Randomise the seed - maybe using the noise on the AnalogIn pins.
liam94 0:506531d0531c 350 */
liam94 0:506531d0531c 351 void randomiseBuffer();
liam94 0:506531d0531c 352
liam94 0:506531d0531c 353 /** Plot Array
liam94 0:506531d0531c 354 *
liam94 0:506531d0531c 355 * This function plots a one-dimensional array in the buffer.
liam94 0:506531d0531c 356 * @param array[] - y values of the plot. Values should be normalised in the range 0.0 to 1.0. First 84 plotted.
liam94 0:506531d0531c 357 */
liam94 0:506531d0531c 358 void plotArray(float const array[]);
liam94 0:506531d0531c 359
liam94 0:506531d0531c 360 /** Draw Circle
liam94 0:506531d0531c 361 *
liam94 0:506531d0531c 362 * This function draws a circle at the specified origin with specified radius in the screen buffer
liam94 0:506531d0531c 363 * Uses the midpoint circle algorithm.
liam94 0:506531d0531c 364 * @see http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
liam94 0:506531d0531c 365 * @param x0 - x-coordinate of centre
liam94 0:506531d0531c 366 * @param y0 - y-coordinate of centre
liam94 0:506531d0531c 367 * @param radius - radius of circle in pixels
liam94 0:506531d0531c 368 * @param fill - fill-type for the shape
liam94 0:506531d0531c 369 */
liam94 0:506531d0531c 370 void drawCircle(unsigned int const x0,
liam94 0:506531d0531c 371 unsigned int const y0,
liam94 0:506531d0531c 372 unsigned int const radius,
liam94 0:506531d0531c 373 FillType const fill);
liam94 0:506531d0531c 374
liam94 0:506531d0531c 375 /** Draw Line
liam94 0:506531d0531c 376 *
liam94 0:506531d0531c 377 * This function draws a line between the specified points using linear interpolation.
liam94 0:506531d0531c 378 * @param x0 - x-coordinate of first point
liam94 0:506531d0531c 379 * @param y0 - y-coordinate of first point
liam94 0:506531d0531c 380 * @param x1 - x-coordinate of last point
liam94 0:506531d0531c 381 * @param y1 - y-coordinate of last point
liam94 0:506531d0531c 382 * @param type - 0 white,1 black,2 dotted
liam94 0:506531d0531c 383 */
liam94 0:506531d0531c 384 void drawLine(unsigned int const x0,
liam94 0:506531d0531c 385 unsigned int const y0,
liam94 0:506531d0531c 386 unsigned int const x1,
liam94 0:506531d0531c 387 unsigned int const y1,
liam94 0:506531d0531c 388 unsigned int const type);
liam94 0:506531d0531c 389
liam94 0:506531d0531c 390 /** Draw Rectangle
liam94 0:506531d0531c 391 *
liam94 0:506531d0531c 392 * This function draws a rectangle.
liam94 0:506531d0531c 393 * @param x0 - x-coordinate of origin (top-left)
liam94 0:506531d0531c 394 * @param y0 - y-coordinate of origin (top-left)
liam94 0:506531d0531c 395 * @param width - width of rectangle
liam94 0:506531d0531c 396 * @param height - height of rectangle
liam94 0:506531d0531c 397 * @param fill - fill-type for the shape
liam94 0:506531d0531c 398 */
liam94 0:506531d0531c 399 void drawRect(unsigned int const x0,
liam94 0:506531d0531c 400 unsigned int const y0,
liam94 0:506531d0531c 401 unsigned int const width,
liam94 0:506531d0531c 402 unsigned int const height,
liam94 0:506531d0531c 403 FillType const fill);
liam94 0:506531d0531c 404
liam94 0:506531d0531c 405 /** Draw Sprite
liam94 0:506531d0531c 406 *
liam94 0:506531d0531c 407 * This function draws a sprite as defined in a 2D array
liam94 0:506531d0531c 408 * @param x0 - x-coordinate of origin (top-left)
liam94 0:506531d0531c 409 * @param y0 - y-coordinate of origin (top-left)
liam94 0:506531d0531c 410 * @param nrows - number of rows in sprite
liam94 0:506531d0531c 411 * @param ncols - number of columns in sprite
liam94 0:506531d0531c 412 * @param sprite - 2D array representing the sprite
liam94 0:506531d0531c 413 */
liam94 0:506531d0531c 414 void drawSprite(int x0,
liam94 0:506531d0531c 415 int y0,
liam94 0:506531d0531c 416 int nrows,
liam94 0:506531d0531c 417 int ncols,
liam94 0:506531d0531c 418 int *sprite);
liam94 0:506531d0531c 419
liam94 0:506531d0531c 420
liam94 0:506531d0531c 421 private:
liam94 0:506531d0531c 422 // methods
liam94 0:506531d0531c 423 void setXYAddress(unsigned int const x,
liam94 0:506531d0531c 424 unsigned int const y);
liam94 0:506531d0531c 425 void initSPI();
liam94 0:506531d0531c 426 void turnOn();
liam94 0:506531d0531c 427 void reset();
liam94 0:506531d0531c 428 void clearRAM();
liam94 0:506531d0531c 429 void sendCommand(unsigned char command);
liam94 0:506531d0531c 430 void sendData(unsigned char data);
liam94 0:506531d0531c 431 void setTempCoefficient(char tc); // 0 to 3
liam94 0:506531d0531c 432 void setBias(char bias); // 0 to 7
liam94 0:506531d0531c 433 };
liam94 0:506531d0531c 434
liam94 0:506531d0531c 435 const unsigned char font5x7[480] = {
liam94 0:506531d0531c 436 0x00, 0x00, 0x00, 0x00, 0x00,// (space)
liam94 0:506531d0531c 437 0x00, 0x00, 0x5F, 0x00, 0x00,// !
liam94 0:506531d0531c 438 0x00, 0x07, 0x00, 0x07, 0x00,// "
liam94 0:506531d0531c 439 0x14, 0x7F, 0x14, 0x7F, 0x14,// #
liam94 0:506531d0531c 440 0x24, 0x2A, 0x7F, 0x2A, 0x12,// $
liam94 0:506531d0531c 441 0x23, 0x13, 0x08, 0x64, 0x62,// %
liam94 0:506531d0531c 442 0x36, 0x49, 0x55, 0x22, 0x50,// &
liam94 0:506531d0531c 443 0x00, 0x05, 0x03, 0x00, 0x00,// '
liam94 0:506531d0531c 444 0x00, 0x1C, 0x22, 0x41, 0x00,// (
liam94 0:506531d0531c 445 0x00, 0x41, 0x22, 0x1C, 0x00,// )
liam94 0:506531d0531c 446 0x08, 0x2A, 0x1C, 0x2A, 0x08,// *
liam94 0:506531d0531c 447 0x08, 0x08, 0x3E, 0x08, 0x08,// +
liam94 0:506531d0531c 448 0x00, 0x50, 0x30, 0x00, 0x00,// ,
liam94 0:506531d0531c 449 0x08, 0x08, 0x08, 0x08, 0x08,// -
liam94 0:506531d0531c 450 0x00, 0x60, 0x60, 0x00, 0x00,// .
liam94 0:506531d0531c 451 0x20, 0x10, 0x08, 0x04, 0x02,// /
liam94 0:506531d0531c 452 0x3E, 0x51, 0x49, 0x45, 0x3E,// 0
liam94 0:506531d0531c 453 0x00, 0x42, 0x7F, 0x40, 0x00,// 1
liam94 0:506531d0531c 454 0x42, 0x61, 0x51, 0x49, 0x46,// 2
liam94 0:506531d0531c 455 0x21, 0x41, 0x45, 0x4B, 0x31,// 3
liam94 0:506531d0531c 456 0x18, 0x14, 0x12, 0x7F, 0x10,// 4
liam94 0:506531d0531c 457 0x27, 0x45, 0x45, 0x45, 0x39,// 5
liam94 0:506531d0531c 458 0x3C, 0x4A, 0x49, 0x49, 0x30,// 6
liam94 0:506531d0531c 459 0x01, 0x71, 0x09, 0x05, 0x03,// 7
liam94 0:506531d0531c 460 0x36, 0x49, 0x49, 0x49, 0x36,// 8
liam94 0:506531d0531c 461 0x06, 0x49, 0x49, 0x29, 0x1E,// 9
liam94 0:506531d0531c 462 0x00, 0x36, 0x36, 0x00, 0x00,// :
liam94 0:506531d0531c 463 0x00, 0x56, 0x36, 0x00, 0x00,// ;
liam94 0:506531d0531c 464 0x00, 0x08, 0x14, 0x22, 0x41,// <
liam94 0:506531d0531c 465 0x14, 0x14, 0x14, 0x14, 0x14,// =
liam94 0:506531d0531c 466 0x41, 0x22, 0x14, 0x08, 0x00,// >
liam94 0:506531d0531c 467 0x02, 0x01, 0x51, 0x09, 0x06,// ?
liam94 0:506531d0531c 468 0x32, 0x49, 0x79, 0x41, 0x3E,// @
liam94 0:506531d0531c 469 0x7E, 0x11, 0x11, 0x11, 0x7E,// A
liam94 0:506531d0531c 470 0x7F, 0x49, 0x49, 0x49, 0x36,// B
liam94 0:506531d0531c 471 0x3E, 0x41, 0x41, 0x41, 0x22,// C
liam94 0:506531d0531c 472 0x7F, 0x41, 0x41, 0x22, 0x1C,// D
liam94 0:506531d0531c 473 0x7F, 0x49, 0x49, 0x49, 0x41,// E
liam94 0:506531d0531c 474 0x7F, 0x09, 0x09, 0x01, 0x01,// F
liam94 0:506531d0531c 475 0x3E, 0x41, 0x41, 0x51, 0x32,// G
liam94 0:506531d0531c 476 0x7F, 0x08, 0x08, 0x08, 0x7F,// H
liam94 0:506531d0531c 477 0x00, 0x41, 0x7F, 0x41, 0x00,// I
liam94 0:506531d0531c 478 0x20, 0x40, 0x41, 0x3F, 0x01,// J
liam94 0:506531d0531c 479 0x7F, 0x08, 0x14, 0x22, 0x41,// K
liam94 0:506531d0531c 480 0x7F, 0x40, 0x40, 0x40, 0x40,// L
liam94 0:506531d0531c 481 0x7F, 0x02, 0x04, 0x02, 0x7F,// M
liam94 0:506531d0531c 482 0x7F, 0x04, 0x08, 0x10, 0x7F,// N
liam94 0:506531d0531c 483 0x3E, 0x41, 0x41, 0x41, 0x3E,// O
liam94 0:506531d0531c 484 0x7F, 0x09, 0x09, 0x09, 0x06,// P
liam94 0:506531d0531c 485 0x3E, 0x41, 0x51, 0x21, 0x5E,// Q
liam94 0:506531d0531c 486 0x7F, 0x09, 0x19, 0x29, 0x46,// R
liam94 0:506531d0531c 487 0x46, 0x49, 0x49, 0x49, 0x31,// S
liam94 0:506531d0531c 488 0x01, 0x01, 0x7F, 0x01, 0x01,// T
liam94 0:506531d0531c 489 0x3F, 0x40, 0x40, 0x40, 0x3F,// U
liam94 0:506531d0531c 490 0x1F, 0x20, 0x40, 0x20, 0x1F,// V
liam94 0:506531d0531c 491 0x7F, 0x20, 0x18, 0x20, 0x7F,// W
liam94 0:506531d0531c 492 0x63, 0x14, 0x08, 0x14, 0x63,// X
liam94 0:506531d0531c 493 0x03, 0x04, 0x78, 0x04, 0x03,// Y
liam94 0:506531d0531c 494 0x61, 0x51, 0x49, 0x45, 0x43,// Z
liam94 0:506531d0531c 495 0x00, 0x00, 0x7F, 0x41, 0x41,// [
liam94 0:506531d0531c 496 0x02, 0x04, 0x08, 0x10, 0x20,// "\"
liam94 0:506531d0531c 497 0x41, 0x41, 0x7F, 0x00, 0x00,// ]
liam94 0:506531d0531c 498 0x04, 0x02, 0x01, 0x02, 0x04,// ^
liam94 0:506531d0531c 499 0x40, 0x40, 0x40, 0x40, 0x40,// _
liam94 0:506531d0531c 500 0x00, 0x01, 0x02, 0x04, 0x00,// `
liam94 0:506531d0531c 501 0x20, 0x54, 0x54, 0x54, 0x78,// a
liam94 0:506531d0531c 502 0x7F, 0x48, 0x44, 0x44, 0x38,// b
liam94 0:506531d0531c 503 0x38, 0x44, 0x44, 0x44, 0x20,// c
liam94 0:506531d0531c 504 0x38, 0x44, 0x44, 0x48, 0x7F,// d
liam94 0:506531d0531c 505 0x38, 0x54, 0x54, 0x54, 0x18,// e
liam94 0:506531d0531c 506 0x08, 0x7E, 0x09, 0x01, 0x02,// f
liam94 0:506531d0531c 507 0x08, 0x14, 0x54, 0x54, 0x3C,// g
liam94 0:506531d0531c 508 0x7F, 0x08, 0x04, 0x04, 0x78,// h
liam94 0:506531d0531c 509 0x00, 0x44, 0x7D, 0x40, 0x00,// i
liam94 0:506531d0531c 510 0x20, 0x40, 0x44, 0x3D, 0x00,// j
liam94 0:506531d0531c 511 0x00, 0x7F, 0x10, 0x28, 0x44,// k
liam94 0:506531d0531c 512 0x00, 0x41, 0x7F, 0x40, 0x00,// l
liam94 0:506531d0531c 513 0x7C, 0x04, 0x18, 0x04, 0x78,// m
liam94 0:506531d0531c 514 0x7C, 0x08, 0x04, 0x04, 0x78,// n
liam94 0:506531d0531c 515 0x38, 0x44, 0x44, 0x44, 0x38,// o
liam94 0:506531d0531c 516 0x7C, 0x14, 0x14, 0x14, 0x08,// p
liam94 0:506531d0531c 517 0x08, 0x14, 0x14, 0x18, 0x7C,// q
liam94 0:506531d0531c 518 0x7C, 0x08, 0x04, 0x04, 0x08,// r
liam94 0:506531d0531c 519 0x48, 0x54, 0x54, 0x54, 0x20,// s
liam94 0:506531d0531c 520 0x04, 0x3F, 0x44, 0x40, 0x20,// t
liam94 0:506531d0531c 521 0x3C, 0x40, 0x40, 0x20, 0x7C,// u
liam94 0:506531d0531c 522 0x1C, 0x20, 0x40, 0x20, 0x1C,// v
liam94 0:506531d0531c 523 0x3C, 0x40, 0x30, 0x40, 0x3C,// w
liam94 0:506531d0531c 524 0x44, 0x28, 0x10, 0x28, 0x44,// x
liam94 0:506531d0531c 525 0x0C, 0x50, 0x50, 0x50, 0x3C,// y
liam94 0:506531d0531c 526 0x44, 0x64, 0x54, 0x4C, 0x44,// z
liam94 0:506531d0531c 527 0x00, 0x08, 0x36, 0x41, 0x00,// {
liam94 0:506531d0531c 528 0x00, 0x00, 0x7F, 0x00, 0x00,// |
liam94 0:506531d0531c 529 0x00, 0x41, 0x36, 0x08, 0x00,// }
liam94 0:506531d0531c 530 0x08, 0x08, 0x2A, 0x1C, 0x08,// ->
liam94 0:506531d0531c 531 0x08, 0x1C, 0x2A, 0x08, 0x08 // <-
liam94 0:506531d0531c 532 };
liam94 0:506531d0531c 533
liam94 0:506531d0531c 534 #endif