Accelerometer and angle meter
N5110 Class Reference
Library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168) using the hardware SPI on the mbed. More...
#include <N5110.h>
Public Member Functions | |
N5110 (PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin) | |
Create a N5110 object connected to the specified pins. | |
void | init () |
Initialise display. | |
void | turnOff () |
Turn off. | |
void | clear () |
Clears. | |
void | normalMode () |
Turn on normal video mode (default) Black on white. | |
void | inverseMode () |
Turn on inverse video mode (default) White on black. | |
void | setBrightness (float brightness) |
Set Brightness. | |
void | printString (const char *str, int x, int y) |
Print String. | |
void | printChar (char c, int x, int y) |
Print Character. | |
void | setPixel (int x, int y) |
Set a Pixel. | |
void | clearPixel (int x, int y) |
Clear a Pixel. | |
int | getPixel (int x, int y) |
Get a Pixel. | |
void | refresh () |
Refresh display. | |
void | randomiseBuffer () |
Randomise buffer. | |
void | plotArray (float array[]) |
Plot Array. | |
void | drawCircle (int x0, int y0, int radius, int fill) |
Draw Circle. | |
void | drawLine (int x0, int y0, int x1, int y1, int type) |
Draw Line. | |
void | drawRect (int x0, int y0, int width, int height, int fill) |
Draw Rectangle. |
Detailed Description
Library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168) using the hardware SPI on the mbed.
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). Can print characters and strings to the display using the included 5x7 font. The library also implements a screen buffer so that individual pixels on the display (84 x 48) can be set, cleared and read. The library can print primitive shapes (lines, circles, rectangles) Acknowledgements to Chris Yan's Nokia_5110 Library.
Revision 1.2
- Date:
- 17th March 2015
Example:
#include "mbed.h" #include "N5110.h" // VCC,SCE,RST,D/C,MOSI,SCLK,LED N5110 lcd(p7,p8,p9,p10,p11,p13,p21); // Can also power (VCC) directly from VOUT (3.3 V) - // Can give better performance due to current limitation from GPIO pin int main() { // first need to initialise display lcd.init(); while(1) { // these are default settings so not strictly needed lcd.normalMode(); // normal colour mode lcd.setBrightness(0.5); // put LED backlight on 50% // can directly print strings at specified co-ordinates lcd.printString("Hello, World!",0,0); char buffer[14]; // each character is 6 pixels wide, screen is 84 pixels (84/6 = 14) // so can display a string of a maximum 14 characters in length // or create formatted strings - ensure they aren't more than 14 characters long int temperature = 27; int length = sprintf(buffer,"T = %2d C",temperature); // print formatted data to buffer // it is important the format specifier ensures the length will fit in the buffer if (length <= 14) // if string will fit on display lcd.printString(buffer,0,1); // display on screen float pressure = 1012.3; // same idea with floats length = sprintf(buffer,"P = %.2f mb",pressure); if (length <= 14) lcd.printString(buffer,0,2); // can also print individual characters at specified place lcd.printChar('X',5,3); // draw a line across the display at y = 40 pixels (origin top-left) for (int i = 0; i < WIDTH; i++) { lcd.setPixel(i,40); } // need to refresh display after setting pixels lcd.refresh(); // can also check status of pixels using getPixel(x,y) wait(5.0); lcd.clear(); // clear display lcd.inverseMode(); // invert colours lcd.setBrightness(1.0); // put LED backlight on full float array[84]; for (int i = 0; i < 84; i++) { array[i] = 0.5 + 0.5*sin(i*2*3.14/84); } // can also plot graphs - 84 elements only // values must be in range 0.0 - 1.0 lcd.plotArray(array); wait(5.0); lcd.clear(); lcd.normalMode(); // normal colour mode back lcd.setBrightness(0.5); // put LED backlight on 50% // example of drawing lines for (int x = 0; x < WIDTH ; x+=10) { // x0,y0,x1,y1,type 0-white,1-black,2-dotted lcd.drawLine(0,0,x,HEIGHT,2); } lcd.refresh(); // need to refresh screen after drawing lines wait(5.0); lcd.clear(); // example of how to draw circles lcd.drawCircle(WIDTH/2,HEIGHT/2,20,1); // x,y,radius,black fill lcd.drawCircle(WIDTH/2,HEIGHT/2,10,2); // x,y,radius,white fill lcd.drawCircle(WIDTH/2,HEIGHT/2,30,0); // x,y,radius,transparent with outline lcd.refresh(); // need to refresh screen after drawing circles wait(5.0); lcd.clear(); // example of how to draw rectangles // origin x,y,width,height,type lcd.drawRect(10,10,50,30,1); // filled black rectangle lcd.drawRect(15,15,20,10,2); // filled white rectange (no outline) lcd.drawRect(2,2,70,40,0); // transparent, just outline lcd.refresh(); // need to refresh screen after drawing rects wait(5.0); lcd.clear(); } }
Definition at line 161 of file N5110.h.
Constructor & Destructor Documentation
N5110 | ( | PinName | pwrPin, |
PinName | scePin, | ||
PinName | rstPin, | ||
PinName | dcPin, | ||
PinName | mosiPin, | ||
PinName | sclkPin, | ||
PinName | ledPin | ||
) |
Create a N5110 object connected to the specified pins.
- Parameters:
-
pwr Pin connected to Vcc on the LCD display (pin 1) sce Pin connected to chip enable (pin 3) rst Pin connected to reset (pin 4) dc Pin connected to data/command select (pin 5) mosi Pin connected to data input (MOSI) (pin 6) sclk Pin connected to serial clock (SCLK) (pin 7) led Pin connected to LED backlight (must be PWM) (pin 8)
Member Function Documentation
void clearPixel | ( | int | x, |
int | y | ||
) |
void drawCircle | ( | int | x0, |
int | y0, | ||
int | radius, | ||
int | fill | ||
) |
Draw Circle.
This function draws a circle at the specified origin with specified radius to the display. Uses the midpoint circle algorithm.
- Parameters:
-
x0 - x-coordinate of centre y0 - y-coordinate of centre radius - radius of circle in pixels fill - 0 transparent (w/outline), 1 filled black, 2 filled white (wo/outline)
void drawLine | ( | int | x0, |
int | y0, | ||
int | x1, | ||
int | y1, | ||
int | type | ||
) |
Draw Line.
This function draws a line between the specified points using linear interpolation.
- Parameters:
-
x0 - x-coordinate of first point y0 - y-coordinate of first point x1 - x-coordinate of last point y1 - y-coordinate of last point type - 0 white,1 black,2 dotted
void drawRect | ( | int | x0, |
int | y0, | ||
int | width, | ||
int | height, | ||
int | fill | ||
) |
Draw Rectangle.
This function draws a rectangle.
- Parameters:
-
x0 - x-coordinate of origin (top-left) y0 - y-coordinate of origin (top-left) width - width of rectangle height - height of rectangle fill - 0 transparent (w/outline), 1 filled black, 2 filled white (wo/outline)
int getPixel | ( | int | x, |
int | y | ||
) |
void init | ( | ) |
void inverseMode | ( | ) |
void normalMode | ( | ) |
void plotArray | ( | float | array[] ) |
void printChar | ( | char | c, |
int | x, | ||
int | y | ||
) |
Print Character.
Sends a character to the display. Printed at the specified location. Character is cut-off after the 83rd pixel.
- Parameters:
-
c - the character to print. Can print ASCII as so printChar('C'). x - the column number (0 to 83) y - the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row
void printString | ( | const char * | str, |
int | x, | ||
int | y | ||
) |
void randomiseBuffer | ( | ) |
Randomise buffer.
This function fills the buffer with random data. Can be used to test the display. A call to refresh() must be made to update the display to reflect the change in pixels. The seed is not set and so the generated pattern will probably be the same each time. TODO: Randomise the seed - maybe using the noise on the AnalogIn pins.
void refresh | ( | ) |
void setBrightness | ( | float | brightness ) |
void setPixel | ( | int | x, |
int | y | ||
) |
Generated on Tue Jul 19 2022 21:33:49 by 1.7.2