Example Pong game for mbed.

Dependencies:   mbed

Committer:
valavanisalex
Date:
Tue Apr 17 08:00:08 2018 +0000
Revision:
11:1447cb7dce3c
Parent:
5:3c9407e2fe55
Correct type error and add documentation

Who changed what in which revision?

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