This is test version of Pokemongo game. ELEC 2645 final project.

Dependencies:   Tone

Committer:
shalwego
Date:
Thu Apr 15 15:35:12 2021 +0000
Revision:
0:819c2d6a69ac
Issue about music playing

Who changed what in which revision?

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