Working Menu, additions to be made

Dependencies:   mbed

Committer:
jackmcgarley
Date:
Wed Aug 24 18:48:25 2022 +0000
Revision:
15:61d9a4e63b99
Parent:
0:d4d7e882c87d
Working menu, additions to be made;

Who changed what in which revision?

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