tr

Revision:
13:908644099648
Parent:
11:fc7d89b33e4c
Child:
15:ee645611ff94
diff -r fc7d89b33e4c -r 908644099648 N5110.h
--- a/N5110.h	Wed Sep 17 11:35:50 2014 +0000
+++ b/N5110.h	Tue Mar 10 19:18:20 2015 +0000
@@ -32,6 +32,10 @@
 #define CMD_VOP_6V06           0xB2
 #define CMD_VOP_7V38           0xC8
 
+// number of pixels on display  
+#define WIDTH 84
+#define HEIGHT 48
+
 #include "mbed.h"
 
 /** 
@@ -50,45 +54,77 @@
  * Example:
  * @code
  
- #include "mbed.h"
- #include "N5110.h"
- 
-  //    VCC,SCE,RST,D/C,MOSI,SCLK,LED
- N5110 lcd(p7,p8,p9,p10,p11,p13,p21);
- 
- int main() {
+#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) {
+
+        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
+        
+        lcd.clear();            // clear display
+        // these are default settings so not strictly needed
+        lcd.normalMode();      // normal colour mode
+        lcd.setBrightness(0.5); // put LED backlight on full
+        
+        // can directly print strings at specified co-ordinates
+        lcd.printString("Hello, World!",0,0);
+
+        // 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);
     
-   // initialise display 
-  lcd.init();
-  // print a string in top-left corner
-  lcd.printString("Hello, World!",0,0);
-  // move cursor to 4th row
-  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
+        // can also print individual characters
+        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); 
 
-  // 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);
- }
+    }
+}
+
   
  * @endcode
  */
@@ -146,14 +182,6 @@
     */
     void setBrightness(float brightness);
     
-    /** Set XY Address
-    * 
-    *   Sets the X and Y address of where the next data sent to the displa will be written in RAM.
-    *   @param  x - the column number (0 to 83) - is automatically incremented after data is written
-    *   @param  y - the row number (0 to 5) - the diplay is split into 6 banks - each bank can be considered a row
-    */
-    void setXYAddress(int x, int y);
-    
     /** Print String
     *
     *   Prints a string of characters to the display.  
@@ -164,11 +192,12 @@
     
     /** Print Character
     *
-    *   Sends a character to the display.  Will be printed at the current address.
-    *   X address is autoincremented by 1 to leave a pixel between successive characters.
+    *   Sends a character to the display.  Printed at the specified location
     *   @param  c - the character to print. Can print ASCII as so printChar('C').
+    *   @param x - the column number (0 to 83)
+    *   @param y - the row number (0 to 5) - the display is split into 6 banks - each bank can be considered a row
     */
-    void printChar(char c);
+    void printChar(char c,int x,int y);
     
     /** Set a Pixel
     *
@@ -224,6 +253,8 @@
     void plotArray(float array[]);
 
 private:
+
+    void setXYAddress(int x, int y);
     void initSPI();
     void turnOn();
     void reset();