Template for the ELEC1620 End of year exam

Dependencies:   mbed

Committer:
el16ttb
Date:
Fri Mar 22 13:11:07 2019 +0000
Revision:
0:54721f063ac8
Initial commit

Who changed what in which revision?

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