Simple library for interfacing to Nokia 5110 LCD display (as found on the SparkFun website). Created by Craig A. Evans, University of Leeds.

Fork of N5110 by Craig Evans

Files at this revision

API Documentation at this revision

Comitter:
eencae
Date:
Wed Jul 16 08:42:27 2014 +0000
Parent:
9:7701f0126ba7
Child:
11:fc7d89b33e4c
Commit message:
Added example code to show how to use sprintf() to print data variables on the display.

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	Tue May 20 19:43:52 2014 +0000
+++ b/N5110.cpp	Wed Jul 16 08:42:27 2014 +0000
@@ -72,7 +72,7 @@
 {
     setBrightness(0.0);  // turn backlight off
     clearRAM();   // clear RAM to ensure specified current consumption
-    // send command to ensure we are in basic model
+    // send command to ensure we are in basic mode
     sendCommand(0x20 | CMD_FS_ACTIVE_MODE | CMD_FS_HORIZONTAL_MODE | CMD_FS_BASIC_MODE);
     // clear the display
     sendCommand(CMD_DC_CLEAR_DISPLAY);
--- a/N5110.h	Tue May 20 19:43:52 2014 +0000
+++ b/N5110.h	Wed Jul 16 08:42:27 2014 +0000
@@ -66,7 +66,27 @@
   lcd.setXYAddress(0,3);
   // print character
   lcd.printChar('X');
-    
+  
+  // data to be printed on display
+  int temperature = 27; 
+  // print formatted data to buffer
+  char buffer[14];  // each character is 6 pixels, screen is 84 pixels (84/6 = 14) 
+  int length = sprintf(buffer,"Temperatu = %2d",temperature); 
+  // it is important the format specifier ensures the string will fit in the buffer
+  // if string will fit on display
+  if (length <= 14)  
+    lcd.printString(buffer,0,4);       // display on screen
+  else
+    lcd.printString("Too long",0,4);  // else print error message
+
+  // same idea with floats
+  float humidity = 9.45;  
+  length = sprintf(buffer,"Humidit = %4.2f",humidity);
+  if (length <= 14)
+    lcd.printString(buffer,0,2);
+  else
+    lcd.printString("Too long",0,2);
+        
   while(1);
  }