200943373MAZE

Dependencies:   mbed

Fork of 200943373MAZE by hongyun AHN

Committer:
hongyunAHN
Date:
Thu May 04 14:08:31 2017 +0000
Revision:
1:bd92ef8d00ac
200943373  hongyun AHN

Who changed what in which revision?

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