85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
|
|
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
|
|
#include <SSD1306Wire.h> // legacy include: `#include "SSD1306.h"
|
|
|
|
// Display Instance
|
|
SSD1306Wire display(0x3c, 21, 22);
|
|
|
|
void oled_init() {
|
|
display.init();
|
|
display.flipScreenVertically();
|
|
display.setFont(ArialMT_Plain_10);
|
|
display.clear();
|
|
display.display();
|
|
}
|
|
|
|
void drawTextFlowDemo(String Text) {
|
|
display.setFont(ArialMT_Plain_10);
|
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
|
display.drawStringMaxWidth(0, 0, 128, Text);
|
|
}
|
|
|
|
void drawTextAlignmentDemo() {
|
|
// Text alignment demo
|
|
display.setFont(ArialMT_Plain_10);
|
|
|
|
// The coordinates define the left starting point of the text
|
|
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
|
display.drawString(0, 10, "Left aligned (0,10)");
|
|
|
|
// The coordinates define the center of the text
|
|
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
|
display.drawString(64, 22, "Center aligned (64,22)");
|
|
|
|
// The coordinates define the right end of the text
|
|
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
|
display.drawString(128, 33, "Right aligned (128,33)");
|
|
}
|
|
|
|
void drawRectDemo() {
|
|
// Draw a pixel at given position
|
|
for (int i = 0; i < 10; i++) {
|
|
display.setPixel(i, i);
|
|
display.setPixel(10 - i, i);
|
|
}
|
|
display.drawRect(12, 12, 20, 20);
|
|
|
|
// Fill the rectangle
|
|
display.fillRect(14, 14, 17, 17);
|
|
|
|
// Draw a line horizontally
|
|
display.drawHorizontalLine(0, 40, 20);
|
|
|
|
// Draw a line horizontally
|
|
display.drawVerticalLine(40, 0, 20);
|
|
}
|
|
|
|
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 Value) {
|
|
int progress = Value;
|
|
// draw the progress bar
|
|
display.drawProgressBar(0, 50, 120, 10, progress);
|
|
|
|
// draw the percentage as String
|
|
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
|
display.drawString(64, 35, String(progress) + "%");
|
|
}
|
|
|
|
void oled_clear() {
|
|
display.clear();
|
|
}
|
|
|
|
void oled_show() {
|
|
display.display();
|
|
}
|