Final Commit

Dependencies:   mbed

Committer:
JRM1986
Date:
Tue May 08 12:32:46 2018 +0000
Revision:
27:bd0f69a75d8b
Parent:
0:53ee0f689634
Final Commit

Who changed what in which revision?

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