shenzhi xu / Mbed 2 deprecated temperature

Dependencies:   mbed

Committer:
xuszdd
Date:
Sun May 10 20:47:53 2015 +0000
Revision:
0:ee32d3554f6f
temperature and pressure

Who changed what in which revision?

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