contains my game for the embedded systems project 2645

Dependencies:   mbed FXOS8700CQQQ

Committer:
OmarAlebiary
Date:
Fri May 03 16:57:52 2019 +0000
Revision:
39:822b66b1c935
Final Submission. I have read and agreed with Statement of Academic Integrity

Who changed what in which revision?

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