Matis Requis 201241242

Dependencies:   mbed

Tempest Game

Game Screen

https://os.mbed.com/media/uploads/MatisRequis/tempest_board_wiki.png The board is made of 12 columns. The Hero stays at the top of the column

Game Controls

https://os.mbed.com/media/uploads/MatisRequis/gamepad_buttons.png

To control the hero spaceship point the joystick to the column you want the hero to go to.

Press the A button to shoot a bullet in the column you are currently in.

Committer:
MatisRequis
Date:
Wed May 27 05:53:03 2020 +0000
Revision:
12:1f1907ebebeb
Parent:
1:03d1c29c2f8a
Final Submission. I have read and agreed with Statement of Academic Integrity

Who changed what in which revision?

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