SO1602A Lib. SO1602A is Organic LED, has 16 chars and 2 lines. This lib supports printf() of C-Language. http://akizukidenshi.com/catalog/g/gP-08276/

Dependents:   NEW_LineTraceHub NEW_LineTraceHub_2 ColorSensorTest

Committer:
AkinoriHashimoto
Date:
Fri Nov 06 06:23:52 2015 +0000
Revision:
4:e17943b827d8
Parent:
3:eaaedd09fa6b
Adj. Constructer, Refer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AkinoriHashimoto 1:eef15a16fe7a 1 /** SO1602A is Organic-LED, and has 16 chars/line and 2 lines.
AkinoriHashimoto 3:eaaedd09fa6b 2 *
AkinoriHashimoto 1:eef15a16fe7a 3 * This librarry supports "printf()" C format.
AkinoriHashimoto 3:eaaedd09fa6b 4 *
AkinoriHashimoto 1:eef15a16fe7a 5 *
AkinoriHashimoto 3:eaaedd09fa6b 6 * @code
AkinoriHashimoto 3:eaaedd09fa6b 7 * #include "mbed.h"
AkinoriHashimoto 3:eaaedd09fa6b 8 * #include "SO1602A.h"
AkinoriHashimoto 3:eaaedd09fa6b 9 * I2C i2c(p28, p27);
AkinoriHashimoto 3:eaaedd09fa6b 10 * SO1602A oled(i2c);
AkinoriHashimoto 3:eaaedd09fa6b 11 * DigitalOut led[]= {LED1, LED2, LED3, LED4};
AkinoriHashimoto 3:eaaedd09fa6b 12 * int main()
AkinoriHashimoto 3:eaaedd09fa6b 13 * {
AkinoriHashimoto 3:eaaedd09fa6b 14 * oled.init();
AkinoriHashimoto 3:eaaedd09fa6b 15 * int iter= 0;
AkinoriHashimoto 3:eaaedd09fa6b 16 * while(true) {
AkinoriHashimoto 3:eaaedd09fa6b 17 * led[0] = !led[0];
AkinoriHashimoto 3:eaaedd09fa6b 18 * oled.printf("iter: %5.5d.", iter);
AkinoriHashimoto 3:eaaedd09fa6b 19 * wait(1.0f);
AkinoriHashimoto 3:eaaedd09fa6b 20 * if(iter%10 == 0) // 10s
AkinoriHashimoto 3:eaaedd09fa6b 21 * oled.clear();
AkinoriHashimoto 3:eaaedd09fa6b 22 * iter++;
AkinoriHashimoto 3:eaaedd09fa6b 23 * }
AkinoriHashimoto 3:eaaedd09fa6b 24 * }
AkinoriHashimoto 3:eaaedd09fa6b 25 * @endcode
AkinoriHashimoto 1:eef15a16fe7a 26 */
AkinoriHashimoto 1:eef15a16fe7a 27
AkinoriHashimoto 0:d8b95544d238 28 #pragma once
AkinoriHashimoto 0:d8b95544d238 29
AkinoriHashimoto 0:d8b95544d238 30 #include "mbed.h"
AkinoriHashimoto 0:d8b95544d238 31
AkinoriHashimoto 3:eaaedd09fa6b 32 // SA0(Pin4); Low: i2c_addr= 0x78, High: 0x7a;
AkinoriHashimoto 0:d8b95544d238 33 // DDRAM addr. Line1: 0x00 ~ 0x0f. Line2: 0x20 ~ 0x2f.
AkinoriHashimoto 0:d8b95544d238 34
AkinoriHashimoto 0:d8b95544d238 35 class SO1602A : public Stream{
AkinoriHashimoto 0:d8b95544d238 36 public:
AkinoriHashimoto 0:d8b95544d238 37 SO1602A (PinName sda, PinName scl, char address= 0x78);
AkinoriHashimoto 0:d8b95544d238 38 SO1602A (I2C &_i2c, char address= 0x78);
AkinoriHashimoto 4:e17943b827d8 39 ~SO1602A();
AkinoriHashimoto 0:d8b95544d238 40 // ******************** printf() future of C-language. ***************************
AkinoriHashimoto 0:d8b95544d238 41
AkinoriHashimoto 0:d8b95544d238 42 /** Initialize
AkinoriHashimoto 0:d8b95544d238 43 */
AkinoriHashimoto 0:d8b95544d238 44 void init();
AkinoriHashimoto 0:d8b95544d238 45
AkinoriHashimoto 0:d8b95544d238 46 /** Clear Display.
AkinoriHashimoto 0:d8b95544d238 47 */
AkinoriHashimoto 0:d8b95544d238 48 void clear();
AkinoriHashimoto 0:d8b95544d238 49
AkinoriHashimoto 0:d8b95544d238 50 /** Set Position of char.
AkinoriHashimoto 0:d8b95544d238 51 * @param col: column, row: rows.
AkinoriHashimoto 0:d8b95544d238 52 */
AkinoriHashimoto 0:d8b95544d238 53 void locate(int col, int row);
AkinoriHashimoto 0:d8b95544d238 54
AkinoriHashimoto 0:d8b95544d238 55 /** Set Contrast.
AkinoriHashimoto 0:d8b95544d238 56 * @param val; 256steps, 0x00 ~ 0xff. Contrast increas as the value.
AkinoriHashimoto 0:d8b95544d238 57 */
AkinoriHashimoto 0:d8b95544d238 58 void setContrast(char val);
AkinoriHashimoto 1:eef15a16fe7a 59
AkinoriHashimoto 1:eef15a16fe7a 60 /** Set Display flag.
AkinoriHashimoto 1:eef15a16fe7a 61 * @parm Enable Display, Cursor turned on, Cursor Blink.
AkinoriHashimoto 1:eef15a16fe7a 62 */
AkinoriHashimoto 3:eaaedd09fa6b 63 void setDispFlag(bool disp= true, bool cursor= true, bool blink= true);
AkinoriHashimoto 0:d8b95544d238 64
AkinoriHashimoto 0:d8b95544d238 65 private:
AkinoriHashimoto 4:e17943b827d8 66 I2C *p_i2c;
AkinoriHashimoto 4:e17943b827d8 67 I2C &i2c;
AkinoriHashimoto 0:d8b95544d238 68 char addr;
AkinoriHashimoto 0:d8b95544d238 69 char buf[3];
AkinoriHashimoto 3:eaaedd09fa6b 70 int col, row;
AkinoriHashimoto 0:d8b95544d238 71
AkinoriHashimoto 0:d8b95544d238 72 bool cmd(char chr);
AkinoriHashimoto 0:d8b95544d238 73
AkinoriHashimoto 0:d8b95544d238 74 // virtual func for printf() in Stream-class.
AkinoriHashimoto 0:d8b95544d238 75 virtual int _putc(int val);
AkinoriHashimoto 0:d8b95544d238 76 virtual int _getc();
AkinoriHashimoto 0:d8b95544d238 77
AkinoriHashimoto 0:d8b95544d238 78 // Function SET
AkinoriHashimoto 0:d8b95544d238 79 void setRE();
AkinoriHashimoto 0:d8b95544d238 80 void clearRE();
AkinoriHashimoto 0:d8b95544d238 81 void setSD();
AkinoriHashimoto 0:d8b95544d238 82 void clearSD();
AkinoriHashimoto 0:d8b95544d238 83
AkinoriHashimoto 0:d8b95544d238 84 };
AkinoriHashimoto 0:d8b95544d238 85
AkinoriHashimoto 0:d8b95544d238 86 // EOF