Zikang Qian / Mbed 2 deprecated el17z2q

Dependencies:   mbed

Fork of el17z2q by ELEC2645 (2017/18)

Committer:
yzjdxl
Date:
Mon May 07 22:11:43 2018 +0000
Branch:
GameEngine
Revision:
2:6dc7bc55c1cb
Parent:
0:f707ce1010fa
publish

Who changed what in which revision?

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