George Sykes ELEC2645 project

Dependencies:   mbed

https://os.mbed.com/media/uploads/el18gs/pixil-frame-0.png

GHOST HUNTER

In a world of ghostly horrors there is much money to be made in underground ghost fighting rings. You've managed to get hold of a Ghostbuster, a special piece of equipment that allows you to catch, train and fight ghosts.

Instructions

Below you will find the instructions for the game. Please note that due to COVID-19 a large part of the game (fighting ghosts) could not be added as it would have required access to a second gamepad which i could not acquire.

Welcome screen

When first started you will be presented with a welcome screen

  • Pot 1 to adjust the contrast on the screen
  • Press A to continue.

Main menu

You have three options, catch ghosts (add ghosts to your inventory), inventory (sell ghosts) or settings(adjust the games settings).

  • Press X and B to move the selection up and down respectively
  • Press A to enter the selected submenu

Catch Ghost

Will now be presented with two challenges. In the first you need to find a ghost, in the second you catch it. Theses stages will start automatically.

Find ghost

Rotate the gamepad on its roll and pitch axis until all the LED's turn on. The ones on the left indicate roll and the right pitch.

  • Rotate the gamepad on it roll and pitch to light up the LED's

Catch ghost

Return the gamepad to a comfortable position and use the joystick to move the crosshairs onto the ghost sprite. When ready press the A button to catch the ghost. You will be told what kind of ghost you have captured and it will be added to your inventory.

  • Press A to catch the ghost
  • Move the joystick to move the crosshairs

Inventory

The inventory allows you to view your ghosts and sell them.

  • Use Pot 1 to scroll through the ghosts
  • Pot 2 to scroll up and down the details of the individual ghosts
  • Press X to prepare to sell a ghost and press again to confirm, if you don't press again the sale screen will disappear after 5 seconds
  • Press Start to return to the main menu

Settings

This menu allows you to adjust some of the settings of the game.

  • Press X to go up one option
  • Press B to go down one option
  • Press A to enter the selected submenu
  • Press Start to return to the main menu

Contrast

Set the contrast of the LCD screen, the contrast will adjust on this screen so you can see the effect (contrast is bounded between 0.4 and 0.6).

  • Pot 1 to increase or decrease the contrast
  • Press A to set the contrast

Button Delay

Set the minimum time between button presses; if this is too low the game will detect two button presses when there was only one, too high and the buttons will seem unresponsive. So as to ensure these issues do not occur while changing the setting button X temporarily operates on the new delay but none of the others will until A is pressed.

  • Pot 1 to increase or decrease the delay
  • Press X to test the new delay, this will toggle the small circle to be filled in or unfilled
  • Press A to save the setting
Committer:
el18gs
Date:
Tue May 26 13:37:32 2020 +0000
Revision:
17:3ebcf7bba112
Parent:
1:8d14be858ca0
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

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