Simple library for interfacing to Nokia 5110 LCD display (as found on the SparkFun website).
Dependents: LabyrinthOfTheMinotaur
Fork of N5110 by
Revision 20:ba8addc061ea, committed 2015-04-23
- Comitter:
- eencae
- Date:
- Thu Apr 23 18:57:52 2015 +0000
- Parent:
- 19:1af393359298
- Commit message:
- 1) Replaced literal values in library with WIDTH, HEIGHT, BANKS etc.; 2) User now needs to manually call refresh() after drawing lines/circles/rects. Was previously in drawLine() and so sent the entire buffer to display after every line - very slow.
Changed in this revision
N5110.cpp | Show annotated file Show diff for this revision Revisions of this file |
N5110.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/N5110.cpp Wed Apr 22 12:41:45 2015 +0000 +++ b/N5110.cpp Thu Apr 23 18:57:52 2015 +0000 @@ -179,6 +179,7 @@ if (x>=0 && x<WIDTH && y>=0 && y<HEIGHT) { // check within range // return relevant bank and mask required bit return (int) buffer[x][y/8] & (1 << y%8); + // note this does not necessarily return 1 - a non-zero number represents a pixel } else { return 0; } @@ -220,11 +221,11 @@ // function to print 5x7 font void N5110::printChar(char c,int x,int y) { - if (y>=0 && y<6) { // check if printing in range of y banks + if (y>=0 && y<BANKS) { // check if printing in range of y banks for (int i = 0; i < 5 ; i++ ) { int pixel_x = x+i; - if (pixel_x > 83) // ensure pixel isn't outside the buffer size (0 - 83) + if (pixel_x > WIDTH-1) // ensure pixel isn't outside the buffer size (0 - 83) break; buffer[pixel_x][y] = font5x7[(c - 32)*5 + i]; // array is offset by 32 relative to ASCII, each character is 5 pixels wide @@ -237,7 +238,7 @@ // function to print string at specified position void N5110::printString(const char * str,int x,int y) { - if (y>=0 && y<6) { // check if printing in range of y banks + if (y>=0 && y<BANKS) { // check if printing in range of y banks int n = 0 ; // counter for number of characters in string // loop through string and print character @@ -247,7 +248,7 @@ // text and pixels can be displayed at the same time for (int i = 0; i < 5 ; i++ ) { int pixel_x = x+i+n*6; - if (pixel_x > 83) // ensure pixel isn't outside the buffer size (0 - 83) + if (pixel_x > WIDTH-1) // ensure pixel isn't outside the buffer size (0 - 83) break; buffer[pixel_x][y] = font5x7[(*str - 32)*5 + i]; } @@ -337,7 +338,6 @@ } } - refresh(); } void N5110::drawLine(int x0,int y0,int x1,int y1,int type) @@ -386,7 +386,6 @@ } } - refresh(); } void N5110::drawRect(int x0,int y0,int width,int height,int fill)
--- a/N5110.h Wed Apr 22 12:41:45 2015 +0000 +++ b/N5110.h Thu Apr 23 18:57:52 2015 +0000 @@ -127,6 +127,7 @@ // 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(); @@ -135,6 +136,7 @@ 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(); @@ -144,8 +146,10 @@ 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); + + wait(5.0); lcd.clear(); }