From 49037cbc3f86237d9fa41b6c1e1f98922c901de9 Mon Sep 17 00:00:00 2001
From: Daniel Eichhorn <dani.eichhorn@squix.ch>
Date: Sun, 18 Mar 2018 08:29:26 +0100
Subject: [PATCH] Simplify two screen demo

---
 .../SSD1306TwoScreenDemo.ino                  | 109 ++----------------
 1 file changed, 7 insertions(+), 102 deletions(-)

diff --git a/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino b/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino
index b108f60..585eb89 100644
--- a/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino
+++ b/examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino
@@ -37,13 +37,6 @@
 SSD1306  display(0x3c, D3, D5);
 SSD1306  display2(0x3c, D1, D2);
 
-
-#define DEMO_DURATION 3000
-typedef void (*Demo)(SSD1306 *display);
-
-int demoMode = 0;
-int counter = 1;
-
 void setup() {
   Serial.begin(115200);
   Serial.println();
@@ -54,120 +47,32 @@ void setup() {
   display.init();
   display2.init();
 
+  // This will make sure that multiple instances of a display driver
+  // running on different ports will work together transparently
   display.setI2cAutoInit(true);
   display2.setI2cAutoInit(true);
 
-
   display.flipScreenVertically();
   display.setFont(ArialMT_Plain_10);
+  display.setTextAlignment(TEXT_ALIGN_LEFT);
 
-  display.flipScreenVertically();
+  display2.flipScreenVertically();
   display2.setFont(ArialMT_Plain_10);
+  display2.setTextAlignment(TEXT_ALIGN_LEFT);
 
 
 
-}
-
-void drawFontFaceDemo(SSD1306 *d) {
-    // Font Demo1
-    // create more fonts at http://oleddisplay.squix.ch/
-    d->setTextAlignment(TEXT_ALIGN_LEFT);
-    d->setFont(ArialMT_Plain_10);
-    d->drawString(0, 0, "Hello world");
-    d->setFont(ArialMT_Plain_16);
-    d->drawString(0, 10, "Hello world");
-    d->setFont(ArialMT_Plain_24);
-    d->drawString(0, 26, "Hello world");
-}
-
-void drawTextFlowDemo(SSD1306 *d) {
-    d->setFont(ArialMT_Plain_10);
-    d->setTextAlignment(TEXT_ALIGN_LEFT);
-    d->drawStringMaxWidth(0, 0, 128,
-      "Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." );
-}
-
-void drawTextAlignmentDemo(SSD1306 *d) {
-    // Text alignment demo
-  d->setFont(ArialMT_Plain_10);
-
-  // The coordinates define the left starting point of the text
-  d->setTextAlignment(TEXT_ALIGN_LEFT);
-  d->drawString(0, 10, "Left aligned (0,10)");
-
-  // The coordinates define the center of the text
-  d->setTextAlignment(TEXT_ALIGN_CENTER);
-  d->drawString(64, 22, "Center aligned (64,22)");
-
-  // The coordinates define the right end of the text
-  d->setTextAlignment(TEXT_ALIGN_RIGHT);
-  d->drawString(128, 33, "Right aligned (128,33)");
-}
-
-void drawRectDemo(SSD1306 *d) {
-      // Draw a pixel at given position
-    for (int i = 0; i < 10; i++) {
-      d->setPixel(i, i);
-      d->setPixel(10 - i, i);
-    }
-    d->drawRect(12, 12, 20, 20);
-
-    // Fill the rectangle
-    d->fillRect(14, 14, 17, 17);
-
-    // Draw a line horizontally
-    d->drawHorizontalLine(0, 40, 20);
-
-    // Draw a line horizontally
-    d->drawVerticalLine(40, 0, 20);
-}
-
-void drawCircleDemo(SSD1306 *d) {
-  for (int i=1; i < 8; i++) {
-    d->setColor(WHITE);
-    d->drawCircle(32, 32, i*3);
-    if (i % 2 == 0) {
-      d->setColor(BLACK);
-    }
-    d->fillCircle(96, 32, 32 - i* 3);
-  }
-}
-
-void drawProgressBarDemo(SSD1306 *d) {
-  int progress = (counter / 5) % 100;
-  // draw the progress bar
-  d->drawProgressBar(0, 32, 120, 10, progress);
-
-  // draw the percentage as String
-  d->setTextAlignment(TEXT_ALIGN_CENTER);
-  d->drawString(64, 15, String(progress) + "%");
-}
 
-void drawImageDemo(SSD1306 *d) {
-    // see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
-    // on how to create xbm files
-    d->drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
 }
 
-
-Demo demos[] = {drawFontFaceDemo, drawTextFlowDemo, drawTextAlignmentDemo, drawRectDemo, drawCircleDemo, drawProgressBarDemo, drawImageDemo};
-int demoLength = (sizeof(demos) / sizeof(Demo));
-long timeSinceLastModeSwitch = 0;
-
 void loop() {
   display.clear();
-  demos[demoMode](&display);
+  display.drawString(0, 0, "Hello world: " + String(millis()));
   display.display();
 
   display2.clear();
-  demos[(demoMode + 1) % demoLength](&display2);
+  display2.drawString(0, 0, "Hello world: " + String(millis()));
   display2.display();
 
-
-  if (millis() - timeSinceLastModeSwitch > DEMO_DURATION) {
-    demoMode = (demoMode + 1)  % demoLength;
-    timeSinceLastModeSwitch = millis();
-  }
-  counter++;
   delay(10);
 }
-- 
GitLab