Library for interfacing to Nokia 5110 LCD display (as found on the SparkFun website).

Dependents:   LV7_LCDtest LV7_Grupa5_Tim003_Zadatak1 lv7_Grupa5_Tim008_zad1 LV7_PAI_Grupa5_tim10_Zadatak1 ... more

This library is designed to make it easy to interface an mbed with a Nokia 5110 LCD display.

These can be found at Sparkfun (https://www.sparkfun.com/products/10168) and Adafruit (http://www.adafruit.com/product/338).

The library uses the SPI peripheral on the mbed which means it is much faster sending data to the display than other libraries available on other platforms that use software SPI.

The library can print strings as well as controlling individual pixels, meaning that both text and primitive graphics can be displayed.

Revision:
42:596c207519de
Parent:
36:00ebd449b6f3
Child:
43:c2598020fcac
--- a/N5110.cpp	Wed Mar 08 16:13:08 2017 +0000
+++ b/N5110.cpp	Tue Mar 21 10:43:19 2017 +0000
@@ -191,11 +191,13 @@
 // Pixels are addressed in the range of 0 to 47 (y) and 0 to 83 (x).  The refresh()
 // function must be called after set and clear in order to update the display
 void N5110::setPixel(unsigned int const x,
-                     unsigned int const y)
+                     unsigned int const y,
+                     bool const         state)
 {
     if (x<WIDTH && y<HEIGHT) {  // check within range
         // calculate bank and shift 1 to required position in the data byte
-        buffer[x][y/8] |= (1 << y%8);
+        if(state) buffer[x][y/8] |= (1 << y%8);
+        else      buffer[x][y/8] &= ~(1 << y%8);
     }
 }
 
@@ -389,10 +391,9 @@
             // do linear interpolation
             int y = y0 + (y1-y0)*(x-x0)/(x1-x0);
 
-            if (type == 0)   // if 'white' line, turn off pixel
-                clearPixel(x,y);
-            else
-                setPixel(x,y);  // else if 'black' or 'dotted' turn on pixel
+            // If the line type is '0', this will clear the pixel
+            // If it is '1' or '2', the pixel will be set
+            setPixel(x,y, type);
         }
     } else {
 
@@ -404,11 +405,9 @@
             // do linear interpolation
             int x = x0 + (x1-x0)*(y-y0)/(y1-y0);
 
-            if (type == 0)   // if 'white' line, turn off pixel
-                clearPixel(x,y);
-            else
-                setPixel(x,y);  // else if 'black' or 'dotted' turn on pixel
-
+            // If the line type is '0', this will clear the pixel
+            // If it is '1' or '2', the pixel will be set
+            setPixel(x,y, type);
         }
     }
 
@@ -434,23 +433,16 @@
 }
 
 void N5110::drawSprite(int x0,
-                      int y0,
-                      int nrows,
-                      int ncols,
-                      int *sprite)
+                       int y0,
+                       int nrows,
+                       int ncols,
+                       int *sprite)
 { 
     for (int i = 0; i < nrows; i++) {
         for (int j = 0 ; j < ncols ; j++) {
 
             int pixel = *((sprite+i*ncols)+j);
-
-            if (pixel) {
-                setPixel(x0+j,y0+i);
-            }
-            else {
-                clearPixel(x0+j,y0+i);    
-            }
-
+            setPixel(x0+j,y0+i, pixel);
         }
     }
 }
\ No newline at end of file