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

Dependents:   aqm1602 FCAS-M101V1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AQM1602.h Source File

AQM1602.h

00001 /**
00002  *  LCD AQM1602 library, refer to http://akizukidenshi.com/catalog/g/gP-08779/.
00003  *  16 chars x 2 lines.
00004  *  I select 20k ohm as pullup resistor.
00005  */
00006 
00007 /** @code
00008  * #include "mbed.h"
00009  * #include "AQM1602.h"
00010  * 
00011  * I2C i2c(p28, p27);
00012  * AQM1602 lcd(i2c);    // if 5.0v supply, (i2c, false);
00013  * DigitalOut led[]= {LED1, LED2, LED3, LED4};
00014  * 
00015  * int main()
00016  * {
00017  *     lcd.init();
00018  *     int iter= 0;
00019  *     while(true) {
00020  *         led[0] = !led[0];
00021  *         lcd.printf("iter: %5.5d.\r\n", iter);
00022  *         wait(1.0f);
00023  *         if(iter%10 == 0)    // 10s
00024  *             lcd.clear();
00025  *         iter++;
00026  *     }
00027  * }
00028  * @endcode
00029  */
00030  
00031 #pragma once
00032 
00033 #include "mbed.h"
00034 
00035 class AQM1602 : public Stream{
00036 public:
00037     AQM1602(PinName sda, PinName scl, bool pw3v3= true, char address= 0x7c);
00038     AQM1602(I2C &_i2c, bool pw3v3= true, char address= 0x7c);
00039     ~AQM1602();
00040 //  ******************** enable printf() future of C-language. ****************
00041     
00042     /** Initialize
00043      */
00044     void init();
00045 
00046     /** Clear Display.
00047      */
00048     void clear();
00049     
00050     /** CR, LF
00051      */
00052     void cr();
00053     void lf();
00054     
00055     /** Set Position of char.
00056      *  @param col: column, row: rows.
00057      */
00058     void locate(int col, int row);
00059     
00060     /** Set Contrast.
00061      *  @param val; 64steps, 0x00 ~ 0x3f. Contrast increas as the value.
00062      *              default: 0x23.
00063      */
00064     void setContrast(char val, bool ctrlIS= true);
00065 
00066     /** Set Display flag.
00067      * @parm Enable Display, Cursor turned on, Cursor Blink.
00068      */
00069     void setDispFlag(bool disp= true, bool cursor= true, bool blink= true);
00070 
00071 private:
00072     // using i2c
00073     I2C *p_i2c;
00074     I2C &i2c;
00075     char addr;          // i2c Addr.
00076     char buf[3];        // i2c to write char space
00077     int wait4cmd;       // waiting time span for sending command.
00078     
00079 //    char valContrast;
00080     int col, row;  // column, row of the LCD panel.
00081     bool vdd3v3;
00082     char contrast;
00083     
00084     void setPwContrast(bool ctrlIS= true);
00085     
00086     bool cmd(char chr);
00087     
00088     // virtual func for printf() in Stream-class.
00089     virtual int _putc(int value);
00090     virtual int _getc();    // return -1.
00091     
00092     void setIS();
00093     void clearIS();
00094 };
00095 
00096 // EOF