ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18ajst

Dependencies:   mbed

Committer:
Albutt
Date:
Wed May 27 00:57:33 2020 +0000
Revision:
24:19994f789276
Parent:
1:a52187d01a78
Testing Documentation

Who changed what in which revision?

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