test

Dependencies:   mbed FXOS8700CQ

Committer:
Neowless
Date:
Fri May 15 20:36:00 2020 +0000
Revision:
4:c7dc43515215
Parent:
1:48b0bf0bcda8
test;

Who changed what in which revision?

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