You can output chars to AQM1602 with printf(). ex. lcd.printf("iter: %5.5d.\r\n", iter);

Dependents:   aqm1602 FCAS-M101V1

Revision:
1:ac441b938a80
Parent:
0:4d904885c9b8
Child:
2:9233e977ee6e
--- a/AQM1602.h	Fri Oct 02 06:13:12 2015 +0000
+++ b/AQM1602.h	Mon Oct 19 02:40:02 2015 +0000
@@ -1,13 +1,43 @@
+/**
+ *  LCD AQM1602 library, refer to http://akizukidenshi.com/catalog/g/gP-08779/.
+ *  16 chars x 2 lines.
+ *  I select 20k ohm as pullup resistor.
+ */
+
+/** @code
+ * #include "mbed.h"
+ * #include "AQM1602.h"
+ * 
+ * I2C i2c(p28, p27);
+ * AQM1602 lcd(i2c);    // if 5.0v supply, (i2c, false);
+ * DigitalOut led[]= {LED1, LED2, LED3, LED4};
+ * 
+ * int main()
+ * {
+ *     lcd.init();
+ *     int iter= 0;
+ *     while(true) {
+ *         led[0] = !led[0];
+ *         lcd.printf("iter: %5.5d.", iter);
+ *         wait(1.0f);
+ *         if(iter%10 == 0)    // 10s
+ *             lcd.clear();
+ *         iter++;
+ *     }
+ * }
+ * @endcode
+ */
+ 
 #pragma once
 
 #include "mbed.h"
 
 class AQM1602 : public Stream{
 public:
-    AQM1602(PinName sda, PinName scl, char address= 0x7c);
-    AQM1602(I2C &_i2c, char address= 0x7c);
+    AQM1602(PinName sda, PinName scl, bool pw3v3= true, char address= 0x7c);
+    AQM1602(I2C &_i2c, bool pw3v3= true, char address= 0x7c);
 
-//  ******************** printf() future of C-language. ***************************
+//  ******************** enable printf() future of C-language. ****************
     
     /** Initialize
      */
@@ -24,27 +54,34 @@
     
     /** Set Contrast.
      *  @param val; 64steps, 0x00 ~ 0x3f. Contrast increas as the value.
+     *              default: 0x23.
      */
     void setContrast(char val, bool ctrlIS= true);
 
     /** Set Display flag.
      * @parm Enable Display, Cursor turned on, Cursor Blink.
      */
-    void setDispFlag(bool disp, bool cursor, bool blink);
+    void setDispFlag(bool disp= true, bool cursor= true, bool blink= true);
 
 private:
-    I2C i2c;
-    char addr;
-    char buf[3];
-    int _column, _row;
-    int wait4cmd;
-    char valContrast;
+    // using i2c
+    I2C i2c;            // i2c Stream.
+    char addr;          // i2c Addr.
+    char buf[3];        // i2c to write char space
+    int wait4cmd;       // waiting time span for sending command.
+    
+//    char valContrast;
+    int col, row;  // column, row of the LCD panel.
+    bool vdd3v3;
+    char contrast;
+    
+    void setPwContrast(bool ctrlIS= true);
     
     bool cmd(char chr);
     
     // virtual func for printf() in Stream-class.
     virtual int _putc(int value);
-    virtual int _getc();
+    virtual int _getc();    // return -1.
     
     void setIS();
     void clearIS();