Skip to content

Commit 49037cb

Browse files
committed
Simplify two screen demo
1 parent f152d1a commit 49037cb

File tree

1 file changed

+7
-102
lines changed

1 file changed

+7
-102
lines changed

examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino

Lines changed: 7 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@
3737
SSD1306 display(0x3c, D3, D5);
3838
SSD1306 display2(0x3c, D1, D2);
3939

40-
41-
#define DEMO_DURATION 3000
42-
typedef void (*Demo)(SSD1306 *display);
43-
44-
int demoMode = 0;
45-
int counter = 1;
46-
4740
void setup() {
4841
Serial.begin(115200);
4942
Serial.println();
@@ -54,120 +47,32 @@ void setup() {
5447
display.init();
5548
display2.init();
5649

50+
// This will make sure that multiple instances of a display driver
51+
// running on different ports will work together transparently
5752
display.setI2cAutoInit(true);
5853
display2.setI2cAutoInit(true);
5954

60-
6155
display.flipScreenVertically();
6256
display.setFont(ArialMT_Plain_10);
57+
display.setTextAlignment(TEXT_ALIGN_LEFT);
6358

64-
display.flipScreenVertically();
59+
display2.flipScreenVertically();
6560
display2.setFont(ArialMT_Plain_10);
61+
display2.setTextAlignment(TEXT_ALIGN_LEFT);
6662

6763

6864

69-
}
70-
71-
void drawFontFaceDemo(SSD1306 *d) {
72-
// Font Demo1
73-
// create more fonts at http://oleddisplay.squix.ch/
74-
d->setTextAlignment(TEXT_ALIGN_LEFT);
75-
d->setFont(ArialMT_Plain_10);
76-
d->drawString(0, 0, "Hello world");
77-
d->setFont(ArialMT_Plain_16);
78-
d->drawString(0, 10, "Hello world");
79-
d->setFont(ArialMT_Plain_24);
80-
d->drawString(0, 26, "Hello world");
81-
}
82-
83-
void drawTextFlowDemo(SSD1306 *d) {
84-
d->setFont(ArialMT_Plain_10);
85-
d->setTextAlignment(TEXT_ALIGN_LEFT);
86-
d->drawStringMaxWidth(0, 0, 128,
87-
"Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." );
88-
}
89-
90-
void drawTextAlignmentDemo(SSD1306 *d) {
91-
// Text alignment demo
92-
d->setFont(ArialMT_Plain_10);
93-
94-
// The coordinates define the left starting point of the text
95-
d->setTextAlignment(TEXT_ALIGN_LEFT);
96-
d->drawString(0, 10, "Left aligned (0,10)");
97-
98-
// The coordinates define the center of the text
99-
d->setTextAlignment(TEXT_ALIGN_CENTER);
100-
d->drawString(64, 22, "Center aligned (64,22)");
101-
102-
// The coordinates define the right end of the text
103-
d->setTextAlignment(TEXT_ALIGN_RIGHT);
104-
d->drawString(128, 33, "Right aligned (128,33)");
105-
}
106-
107-
void drawRectDemo(SSD1306 *d) {
108-
// Draw a pixel at given position
109-
for (int i = 0; i < 10; i++) {
110-
d->setPixel(i, i);
111-
d->setPixel(10 - i, i);
112-
}
113-
d->drawRect(12, 12, 20, 20);
114-
115-
// Fill the rectangle
116-
d->fillRect(14, 14, 17, 17);
117-
118-
// Draw a line horizontally
119-
d->drawHorizontalLine(0, 40, 20);
120-
121-
// Draw a line horizontally
122-
d->drawVerticalLine(40, 0, 20);
123-
}
124-
125-
void drawCircleDemo(SSD1306 *d) {
126-
for (int i=1; i < 8; i++) {
127-
d->setColor(WHITE);
128-
d->drawCircle(32, 32, i*3);
129-
if (i % 2 == 0) {
130-
d->setColor(BLACK);
131-
}
132-
d->fillCircle(96, 32, 32 - i* 3);
133-
}
134-
}
135-
136-
void drawProgressBarDemo(SSD1306 *d) {
137-
int progress = (counter / 5) % 100;
138-
// draw the progress bar
139-
d->drawProgressBar(0, 32, 120, 10, progress);
140-
141-
// draw the percentage as String
142-
d->setTextAlignment(TEXT_ALIGN_CENTER);
143-
d->drawString(64, 15, String(progress) + "%");
144-
}
14565

146-
void drawImageDemo(SSD1306 *d) {
147-
// see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
148-
// on how to create xbm files
149-
d->drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
15066
}
15167

152-
153-
Demo demos[] = {drawFontFaceDemo, drawTextFlowDemo, drawTextAlignmentDemo, drawRectDemo, drawCircleDemo, drawProgressBarDemo, drawImageDemo};
154-
int demoLength = (sizeof(demos) / sizeof(Demo));
155-
long timeSinceLastModeSwitch = 0;
156-
15768
void loop() {
15869
display.clear();
159-
demos[demoMode](&display);
70+
display.drawString(0, 0, "Hello world: " + String(millis()));
16071
display.display();
16172

16273
display2.clear();
163-
demos[(demoMode + 1) % demoLength](&display2);
74+
display2.drawString(0, 0, "Hello world: " + String(millis()));
16475
display2.display();
16576

166-
167-
if (millis() - timeSinceLastModeSwitch > DEMO_DURATION) {
168-
demoMode = (demoMode + 1) % demoLength;
169-
timeSinceLastModeSwitch = millis();
170-
}
171-
counter++;
17277
delay(10);
17378
}

0 commit comments

Comments
 (0)