diff --git a/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino b/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino index 6a46bd32219d6cecb4ebb77747ed488a93f38aa5..a093b28043f11bd9d991e55ea2a96516aa295114 100644 --- a/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino +++ b/examples/SSD1306ClockDemo/SSD1306ClockDemo.ino @@ -26,13 +26,38 @@ #include <Wire.h> #include <TimeLib.h> -#include "SSD1306.h" -#include "SSD1306Ui.h" #include "images.h" -// Initialize the OLED display on address 0x3c -SSD1306 display(0x3c, 5, 4); -SSD1306Ui ui ( &display ); +// Include the correct display library +// For a connection via I2C using Wire include +#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"` +// For a connection via I2C using brzo_i2c (must be installed) include +// #include "SSD1306Brzo.h" +// For a connection via SPI include +// #include "SSD1306Spi.h" + +// Include the UI lib +#include "OLEDDisplayUi.h" + +// Use the corresponding display class: + +// Initialize the OLED display using SPI +// D5 -> SCL +// D7 -> SDA +// D0 -> RES +// D2 -> DC +// D8 -> CS +// SSD1306Spi display(D0, D2, D8); + +// Initialize the OLED display using brzo_i2c +// D3 -> SDA +// D4 -> SCL +// SSD1306Brzo display(0x3c, D3, D5); + +// Initialize the OLED display using Wire library +SSD1306 display(0x3c, D3, D5); + +OLEDDisplayUi ui ( &display ); int screenW = 128; int screenH = 64; @@ -51,11 +76,11 @@ String twoDigits(int digits){ } } -void clockOverlay(SSD1306 *display, SSD1306UiState* state) { +void clockOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) { } -void analogClockFrame(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { +void analogClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { // ui.disableIndicator(); // Draw the clock face @@ -73,30 +98,30 @@ void analogClockFrame(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_ int y3 = ( clockCenterY - ( cos(angle) * ( clockRadius - ( clockRadius / 8 ) ) ) ); display->drawLine( x2 + x , y2 + y , x3 + x , y3 + y); } - + // display second hand float angle = second() * 6 ; - angle = ( angle / 57.29577951 ) ; //Convert degrees to radians + angle = ( angle / 57.29577951 ) ; //Convert degrees to radians int x3 = ( clockCenterX + ( sin(angle) * ( clockRadius - ( clockRadius / 5 ) ) ) ); int y3 = ( clockCenterY - ( cos(angle) * ( clockRadius - ( clockRadius / 5 ) ) ) ); display->drawLine( clockCenterX + x , clockCenterY + y , x3 + x , y3 + y); // // display minute hand angle = minute() * 6 ; - angle = ( angle / 57.29577951 ) ; //Convert degrees to radians + angle = ( angle / 57.29577951 ) ; //Convert degrees to radians x3 = ( clockCenterX + ( sin(angle) * ( clockRadius - ( clockRadius / 4 ) ) ) ); y3 = ( clockCenterY - ( cos(angle) * ( clockRadius - ( clockRadius / 4 ) ) ) ); display->drawLine( clockCenterX + x , clockCenterY + y , x3 + x , y3 + y); // // display hour hand angle = hour() * 30 + int( ( minute() / 12 ) * 6 ) ; - angle = ( angle / 57.29577951 ) ; //Convert degrees to radians + angle = ( angle / 57.29577951 ) ; //Convert degrees to radians x3 = ( clockCenterX + ( sin(angle) * ( clockRadius - ( clockRadius / 2 ) ) ) ); y3 = ( clockCenterY - ( cos(angle) * ( clockRadius - ( clockRadius / 2 ) ) ) ); display->drawLine( clockCenterX + x , clockCenterY + y , x3 + x , y3 + y); } -void digitalClockFrame(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { +void digitalClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { String timenow = String(hour())+":"+twoDigits(minute())+":"+twoDigits(second()); display->setTextAlignment(TEXT_ALIGN_CENTER); display->setFont(ArialMT_Plain_24); @@ -154,8 +179,8 @@ void setup() { const unsigned long seventyYears = 2208988800UL; // subtract seventy years: unsigned long epoch = secsSinceStart - seventyYears * SECS_PER_HOUR; - setTime(epoch); - + setTime(epoch); + } @@ -172,4 +197,3 @@ void loop() { } - diff --git a/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino b/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino index 14fd12b8b6cf4ac2a4cb35c104dea56f5388e35a..8b7b8b58743086f4eeaffb5c93acdb7f3d1311f8 100644 --- a/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino +++ b/examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino @@ -24,17 +24,37 @@ */ #include <Wire.h> -#include "SSD1306.h" #include "images.h" -#define DEMO_DURATION 3000 -typedef void (*Demo)(void); +// Include the correct display library +// For a connection via I2C using Wire include +#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"` +// For a connection via I2C using brzo_i2c (must be installed) include +// #include "SSD1306Brzo.h" +// For a connection via SPI include +// #include "SSD1306Spi.h" + +// Use the corresponding display class: -// Initialize the OLED display on address 0x3c -// D3 and D4 are the pin names on the NodeMCU. Change to int values -// if get compilation errors -SSD1306 display(0x3c, D3, D4); +// Initialize the OLED display using SPI +// D5 -> SCL +// D7 -> SDA +// D0 -> RES +// D2 -> DC +// D8 -> CS +// SSD1306Spi display(D0, D2, D8); +// Initialize the OLED display using brzo_i2c +// D3 -> SDA +// D4 -> SCL +// SSD1306Brzo display(0x3c, D3, D5); + +// Initialize the OLED display using Wire library +SSD1306 display(0x3c, D3, D5); + + +#define DEMO_DURATION 3000 +typedef void (*Demo)(void); int demoMode = 0; int counter = 1; @@ -68,7 +88,7 @@ void drawFontFaceDemo() { void drawTextFlowDemo() { display.setFont(ArialMT_Plain_10); display.setTextAlignment(TEXT_ALIGN_LEFT); - display.drawStringMaxWidth(0, 0, 128, + display.drawStringMaxWidth(0, 0, 128, "Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." ); } @@ -105,7 +125,7 @@ void drawRectDemo() { // Draw a line horizontally display.drawVerticalLine(40, 0, 20); -} +} void drawCircleDemo() { for (int i=1; i < 8; i++) { @@ -143,7 +163,7 @@ void loop() { display.clear(); // draw the current demo method demos[demoMode](); - + display.setTextAlignment(TEXT_ALIGN_RIGHT); display.drawString(10, 128, String(millis())); // write the buffer to the display @@ -156,4 +176,3 @@ void loop() { counter++; delay(10); } - diff --git a/examples/SSD1306UiDemo/SSD1306UiDemo.ino b/examples/SSD1306UiDemo/SSD1306UiDemo.ino index 604dab144699ffe921d0c8f3c55ad8c17a5fa299..edf198f8ab2a512215d493908e0a5686b13370ee 100644 --- a/examples/SSD1306UiDemo/SSD1306UiDemo.ino +++ b/examples/SSD1306UiDemo/SSD1306UiDemo.ino @@ -25,22 +25,47 @@ */ #include <Wire.h> -#include "SSD1306.h" -#include "SSD1306Ui.h" #include "images.h" -// Initialize the OLED display on address 0x3c -SSD1306 display(0x3c, D3, D4); -SSD1306Ui ui ( &display ); +// Include the correct display library +// For a connection via I2C using Wire include +#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"` +// For a connection via I2C using brzo_i2c (must be installed) include +// #include "SSD1306Brzo.h" +// For a connection via SPI include +// #include "SSD1306Spi.h" -void msOverlay(SSD1306 *display, SSD1306UiState* state) { +// Include the UI lib +#include "OLEDDisplayUi.h" + +// Use the corresponding display class: + +// Initialize the OLED display using SPI +// D5 -> SCL +// D7 -> SDA +// D0 -> RES +// D2 -> DC +// D8 -> CS +// SSD1306Spi display(D0, D2, D8); + +// Initialize the OLED display using brzo_i2c +// D3 -> SDA +// D4 -> SCL +// SSD1306Brzo display(0x3c, D3, D5); + +// Initialize the OLED display using Wire library +SSD1306 display(0x3c, D3, D5); + +OLEDDisplayUi ui ( &display ); + +void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) { display->setTextAlignment(TEXT_ALIGN_RIGHT); display->setFont(ArialMT_Plain_10); display->drawString(128, 0, String(millis())); } -void drawFrame1(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { +void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { // draw an xbm image. // Please note that everything that should be transitioned // needs to be drawn relative to x and y @@ -48,7 +73,7 @@ void drawFrame1(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { display->drawXbm(x + 34, y + 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits); } -void drawFrame2(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { +void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { // Demonstrates the 3 included default sizes. The fonts come from SSD1306Fonts.h file // Besides the default fonts there will be a program to convert TrueType fonts into this format display->setTextAlignment(TEXT_ALIGN_LEFT); @@ -62,7 +87,7 @@ void drawFrame2(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { display->drawString(0 + x, 34 + y, "Arial 24"); } -void drawFrame3(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { +void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { // Text alignment demo display->setFont(ArialMT_Plain_10); @@ -79,7 +104,7 @@ void drawFrame3(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { display->drawString(128 + x, 33 + y, "Right aligned (128,33)"); } -void drawFrame4(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { +void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { // Demo for drawStringMaxWidth: // with the third parameter you can define the width after which words will be wrapped. // Currently only spaces and "-" are allowed for wrapping @@ -88,8 +113,8 @@ void drawFrame4(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { display->drawStringMaxWidth(0 + x, 10 + y, 128, "Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore."); } -void drawFrame5(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) { - +void drawFrame5(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) { + } // This array keeps function pointers to all frames @@ -139,9 +164,6 @@ void setup() { display.flipScreenVertically(); - - - } @@ -153,9 +175,5 @@ void loop() { // Don't do stuff if you are below your // time budget. delay(remainingTimeBudget); - } - - } -