demo

Dependencies:   mbed

Committer:
sjuzyz
Date:
Mon Apr 27 13:42:41 2020 +0000
Revision:
0:6fe791dc9958
demo

Who changed what in which revision?

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