tr

Committer:
eencae
Date:
Wed Nov 01 20:48:05 2017 +0000
Revision:
44:57f9d32fb521
Parent:
42:596c207519de
Child:
45:97e54ea40dac
Separated out contrast, bias and temp coefficient methods. Modified init method to take this into account. Can now dynamically control contrast at run-time which makes it easier to account for natural variation between individual LCD displays.

Who changed what in which revision?

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