ELEC2645 (2018/19) / Mbed 2 deprecated fy14lkaa

Dependencies:   mbed

Committer:
fy14lkaa
Date:
Fri Mar 22 20:36:54 2019 +0000
Revision:
0:e2af4c8e462e
Child:
128:a3f581b8461c
initial commit

Who changed what in which revision?

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