6666666666

Dependencies:   Joystick

Committer:
Jenny121
Date:
Mon May 06 09:40:20 2019 +0000
Revision:
1:dfa872e88821
6666666666666666

Who changed what in which revision?

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