#include <Wire.h>
#include <SH1106.h>
int counter = 1;
SH1106 display(0x3c, SDA, SCL);
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
display.init();
display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
}
void drawFontFaceDemo() {
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "Hello world");
display.setFont(ArialMT_Plain_16);
display.drawString(0, 10, "Hello world");
display.setFont(ArialMT_Plain_24);
display.drawString(0, 26, "Hello world");
}
void drawTextFlowDemo() {
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawStringMaxWidth(0, 0, 128,
"Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." );
}
void drawTextAlignmentDemo() {
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, 10, "Left aligned (0,10)");
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64, 22, "Center aligned (64,22)");
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128, 33, "Right aligned (128,33)");
}
void drawRectDemo() {
for (int i = 0; i < 10; i++) {
display.setPixel(i, i);
display.setPixel(10 - i, i);
}
display.drawRect(12, 12, 20, 20);
display.fillRect(14, 14, 17, 17);// Fill the rectangle
display.drawHorizontalLine(0, 40, 20);// Draw a line horizontally
display.drawVerticalLine(40, 0, 20); // Draw a line horizontally
}
void drawCircleDemo() {
for (int i=1; i < 8; i++) {
display.setColor(WHITE);
display.drawCircle(32, 32, i*3);
if (i % 2 == 0) {
display.setColor(BLACK);
}
display.fillCircle(96, 32, 32 - i* 3);
}
}
void drawProgressBarDemo() {
int progress = (counter / 5) % 100;
display.drawProgressBar(0, 32, 120, 10, progress);
display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64, 15, String(progress) + "%");
counter++;
}
void loop() {
display.clear();
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(10, 128, String(millis()));
display.display(); delay(1000);
drawFontFaceDemo();
display.display(); delay(1000);display.clear();
drawTextFlowDemo();
display.display(); delay(1000);display.clear();
drawTextAlignmentDemo();
display.display(); delay(1000);display.clear();
drawRectDemo();
display.display(); delay(1000);display.clear();
drawCircleDemo();
display.display(); delay(1000);display.clear();
drawProgressBarDemo();
display.display();delay(1000);display.clear();
}