deemo1

Dependencies:   mbed

Committer:
haoyan
Date:
Tue Apr 28 14:38:02 2020 +0000
Revision:
0:08b2bdddf22e
deemo

Who changed what in which revision?

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