A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Thu May 09 14:56:46 2019 +0000
Revision:
61:901871a7c6ff
Parent:
33:4f3948dcd2f7
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

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