James Heavey / Mbed 2 deprecated 2665-Breakout-Game

Dependencies:   mbed

Committer:
jamesheavey
Date:
Tue Jan 05 01:14:11 2021 +0000
Revision:
0:92b180c8d407
test

Who changed what in which revision?

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