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