Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

https://os.mbed.com/media/uploads/evanso/84bc1a30759fd6a1e3f1fd1fae3e97c2.png

Hello, soldier, you have been specially selected as the defender of planet earth.

Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.

But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.

As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.

Committer:
evanso
Date:
Wed May 27 02:06:05 2020 +0000
Revision:
87:832ca78426b5
Parent:
9:1ddb8dc93e48
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

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