ELEC2645 (2018/19) / Mbed 2 deprecated el17ebs

Dependencies:   mbed FATFileSystem

Committer:
ellisbhastroud
Date:
Tue Mar 12 14:38:03 2019 +0000
Revision:
0:c6ceddb241df
initial commit

Who changed what in which revision?

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