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