![](/media/cache/profiles/pista-2018.jpg.50x50_q85.jpg)
OLED I2C demo for the SSD1306 and SH1106 displays
Dependencies: mbed OLED_SSD1306_SH1106
main.cpp@2:330a46b0b876, 2022-02-02 (annotated)
- Committer:
- cspista
- Date:
- Wed Feb 02 18:18:25 2022 +0000
- Revision:
- 2:330a46b0b876
- Parent:
- 1:ec7f794146bb
OLED_SSD1306_SH1106 library updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cspista | 0:7696eb63de12 | 1 | /* |
cspista | 0:7696eb63de12 | 2 | * OLED I2C display demo based on the Adafruit_GFX |
cspista | 0:7696eb63de12 | 3 | * library forked from Neal Horman |
cspista | 0:7696eb63de12 | 4 | * Link: https://os.mbed.com/users/nkhorman/code/Adafruit_GFX/ |
cspista | 0:7696eb63de12 | 5 | * The library was modified and extended so that it could be used |
cspista | 0:7696eb63de12 | 6 | * also for 128x64 I2C OLED displays driven by SH1106 controller. |
cspista | 0:7696eb63de12 | 7 | * See the documentation page for Adafruit_SH1106_I2c |
cspista | 0:7696eb63de12 | 8 | */ |
cspista | 0:7696eb63de12 | 9 | |
cspista | 0:7696eb63de12 | 10 | #include "mbed.h" |
cspista | 0:7696eb63de12 | 11 | #include "Adafruit_SSD1306.h" |
cspista | 0:7696eb63de12 | 12 | |
cspista | 0:7696eb63de12 | 13 | I2C i2c(D14,D15); |
cspista | 0:7696eb63de12 | 14 | Adafruit_SH1106_I2c oled(i2c, NC, 0x78, 64, 128); // SH1106 I2C 128x64, with no reset pin |
cspista | 0:7696eb63de12 | 15 | // Adafruit_SSD1306_I2c oled(i2c, NC, 0x78, 64, 128); // SSD1306 I2C 128x64, with no reset pin |
cspista | 0:7696eb63de12 | 16 | // Adafruit_SSD1306_I2c oled(i2c, NC, 0x78, 32, 128); // SSD1306 I2C 128x32, with no reset pin |
cspista | 0:7696eb63de12 | 17 | |
cspista | 0:7696eb63de12 | 18 | int main() |
cspista | 0:7696eb63de12 | 19 | { |
cspista | 0:7696eb63de12 | 20 | uint16_t x=0; |
cspista | 0:7696eb63de12 | 21 | i2c.frequency(400000); |
cspista | 0:7696eb63de12 | 22 | oled.setRotation(0); |
cspista | 0:7696eb63de12 | 23 | oled.clearDisplay(); |
cspista | 0:7696eb63de12 | 24 | oled.drawRect(0,0,oled.width(),oled.height(),1); |
cspista | 0:7696eb63de12 | 25 | oled.display(); |
cspista | 1:ec7f794146bb | 26 | oled.setTextColor(WHITE); |
cspista | 0:7696eb63de12 | 27 | oled.setTextSize(1); |
cspista | 0:7696eb63de12 | 28 | oled.setTextCursor(10,8); |
cspista | 0:7696eb63de12 | 29 | oled.printf("SH1106 %ux%u",oled.width(),oled.height()); |
cspista | 0:7696eb63de12 | 30 | oled.display(); |
cspista | 0:7696eb63de12 | 31 | wait(2.0); |
cspista | 0:7696eb63de12 | 32 | oled.setTextSize(2); |
cspista | 0:7696eb63de12 | 33 | while(1) { |
cspista | 0:7696eb63de12 | 34 | oled.clearDisplay(); |
cspista | 0:7696eb63de12 | 35 | oled.drawRect(0,0,oled.width(),oled.height(),1); |
cspista | 0:7696eb63de12 | 36 | oled.setTextCursor(10,8); |
cspista | 0:7696eb63de12 | 37 | oled.printf("x = %u",x++); |
cspista | 0:7696eb63de12 | 38 | oled.display(); |
cspista | 0:7696eb63de12 | 39 | wait(1.0); |
cspista | 0:7696eb63de12 | 40 | } |
cspista | 0:7696eb63de12 | 41 | } |