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