Coursework

Committer:
sesa514652
Date:
Thu Feb 03 22:03:36 2022 +0000
Revision:
40:0d55297c8b34
Parent:
0:1f799c7cce2b
more functions

Who changed what in which revision?

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