publish my project

Dependencies:   mbed

Committer:
dongyuhu
Date:
Mon Apr 27 06:14:34 2020 +0000
Revision:
0:9e95a5ef2659
initial commit

Who changed what in which revision?

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