el15mh 200929957

Dependencies:   mbed

Committer:
el15mh
Date:
Thu May 04 17:39:23 2017 +0000
Revision:
10:989e5dbd12ee
Parent:
9:960dfc71c224
Documented and final revision

Who changed what in which revision?

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