Skip to content

Commit 635f2ac

Browse files
committed
Update examples
1 parent 7b4e583 commit 635f2ac

File tree

3 files changed

+106
-45
lines changed

3 files changed

+106
-45
lines changed

examples/SSD1306ClockDemo/SSD1306ClockDemo.ino

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,38 @@
2626

2727
#include <Wire.h>
2828
#include <TimeLib.h>
29-
#include "SSD1306.h"
30-
#include "SSD1306Ui.h"
3129
#include "images.h"
3230

33-
// Initialize the OLED display on address 0x3c
34-
SSD1306 display(0x3c, 5, 4);
35-
SSD1306Ui ui ( &display );
31+
// Include the correct display library
32+
// For a connection via I2C using Wire include
33+
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
34+
// For a connection via I2C using brzo_i2c (must be installed) include
35+
// #include "SSD1306Brzo.h"
36+
// For a connection via SPI include
37+
// #include "SSD1306Spi.h"
38+
39+
// Include the UI lib
40+
#include "OLEDDisplayUi.h"
41+
42+
// Use the corresponding display class:
43+
44+
// Initialize the OLED display using SPI
45+
// D5 -> SCL
46+
// D7 -> SDA
47+
// D0 -> RES
48+
// D2 -> DC
49+
// D8 -> CS
50+
// SSD1306Spi display(D0, D2, D8);
51+
52+
// Initialize the OLED display using brzo_i2c
53+
// D3 -> SDA
54+
// D4 -> SCL
55+
// SSD1306Brzo display(0x3c, D3, D5);
56+
57+
// Initialize the OLED display using Wire library
58+
SSD1306 display(0x3c, D3, D5);
59+
60+
OLEDDisplayUi ui ( &display );
3661

3762
int screenW = 128;
3863
int screenH = 64;
@@ -51,11 +76,11 @@ String twoDigits(int digits){
5176
}
5277
}
5378

54-
void clockOverlay(SSD1306 *display, SSD1306UiState* state) {
79+
void clockOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
5580

5681
}
5782

58-
void analogClockFrame(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
83+
void analogClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
5984
// ui.disableIndicator();
6085

6186
// Draw the clock face
@@ -73,30 +98,30 @@ void analogClockFrame(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_
7398
int y3 = ( clockCenterY - ( cos(angle) * ( clockRadius - ( clockRadius / 8 ) ) ) );
7499
display->drawLine( x2 + x , y2 + y , x3 + x , y3 + y);
75100
}
76-
101+
77102
// display second hand
78103
float angle = second() * 6 ;
79-
angle = ( angle / 57.29577951 ) ; //Convert degrees to radians
104+
angle = ( angle / 57.29577951 ) ; //Convert degrees to radians
80105
int x3 = ( clockCenterX + ( sin(angle) * ( clockRadius - ( clockRadius / 5 ) ) ) );
81106
int y3 = ( clockCenterY - ( cos(angle) * ( clockRadius - ( clockRadius / 5 ) ) ) );
82107
display->drawLine( clockCenterX + x , clockCenterY + y , x3 + x , y3 + y);
83108
//
84109
// display minute hand
85110
angle = minute() * 6 ;
86-
angle = ( angle / 57.29577951 ) ; //Convert degrees to radians
111+
angle = ( angle / 57.29577951 ) ; //Convert degrees to radians
87112
x3 = ( clockCenterX + ( sin(angle) * ( clockRadius - ( clockRadius / 4 ) ) ) );
88113
y3 = ( clockCenterY - ( cos(angle) * ( clockRadius - ( clockRadius / 4 ) ) ) );
89114
display->drawLine( clockCenterX + x , clockCenterY + y , x3 + x , y3 + y);
90115
//
91116
// display hour hand
92117
angle = hour() * 30 + int( ( minute() / 12 ) * 6 ) ;
93-
angle = ( angle / 57.29577951 ) ; //Convert degrees to radians
118+
angle = ( angle / 57.29577951 ) ; //Convert degrees to radians
94119
x3 = ( clockCenterX + ( sin(angle) * ( clockRadius - ( clockRadius / 2 ) ) ) );
95120
y3 = ( clockCenterY - ( cos(angle) * ( clockRadius - ( clockRadius / 2 ) ) ) );
96121
display->drawLine( clockCenterX + x , clockCenterY + y , x3 + x , y3 + y);
97122
}
98123

99-
void digitalClockFrame(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
124+
void digitalClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
100125
String timenow = String(hour())+":"+twoDigits(minute())+":"+twoDigits(second());
101126
display->setTextAlignment(TEXT_ALIGN_CENTER);
102127
display->setFont(ArialMT_Plain_24);
@@ -154,8 +179,8 @@ void setup() {
154179
const unsigned long seventyYears = 2208988800UL;
155180
// subtract seventy years:
156181
unsigned long epoch = secsSinceStart - seventyYears * SECS_PER_HOUR;
157-
setTime(epoch);
158-
182+
setTime(epoch);
183+
159184
}
160185

161186

@@ -172,4 +197,3 @@ void loop() {
172197

173198

174199
}
175-

examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,37 @@
2424
*/
2525

2626
#include <Wire.h>
27-
#include "SSD1306.h"
2827
#include "images.h"
2928

30-
#define DEMO_DURATION 3000
31-
typedef void (*Demo)(void);
29+
// Include the correct display library
30+
// For a connection via I2C using Wire include
31+
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
32+
// For a connection via I2C using brzo_i2c (must be installed) include
33+
// #include "SSD1306Brzo.h"
34+
// For a connection via SPI include
35+
// #include "SSD1306Spi.h"
36+
37+
// Use the corresponding display class:
3238

33-
// Initialize the OLED display on address 0x3c
34-
// D3 and D4 are the pin names on the NodeMCU. Change to int values
35-
// if get compilation errors
36-
SSD1306 display(0x3c, D3, D4);
39+
// Initialize the OLED display using SPI
40+
// D5 -> SCL
41+
// D7 -> SDA
42+
// D0 -> RES
43+
// D2 -> DC
44+
// D8 -> CS
45+
// SSD1306Spi display(D0, D2, D8);
3746

47+
// Initialize the OLED display using brzo_i2c
48+
// D3 -> SDA
49+
// D4 -> SCL
50+
// SSD1306Brzo display(0x3c, D3, D5);
51+
52+
// Initialize the OLED display using Wire library
53+
SSD1306 display(0x3c, D3, D5);
54+
55+
56+
#define DEMO_DURATION 3000
57+
typedef void (*Demo)(void);
3858

3959
int demoMode = 0;
4060
int counter = 1;
@@ -68,7 +88,7 @@ void drawFontFaceDemo() {
6888
void drawTextFlowDemo() {
6989
display.setFont(ArialMT_Plain_10);
7090
display.setTextAlignment(TEXT_ALIGN_LEFT);
71-
display.drawStringMaxWidth(0, 0, 128,
91+
display.drawStringMaxWidth(0, 0, 128,
7292
"Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." );
7393
}
7494

@@ -105,7 +125,7 @@ void drawRectDemo() {
105125

106126
// Draw a line horizontally
107127
display.drawVerticalLine(40, 0, 20);
108-
}
128+
}
109129

110130
void drawCircleDemo() {
111131
for (int i=1; i < 8; i++) {
@@ -143,7 +163,7 @@ void loop() {
143163
display.clear();
144164
// draw the current demo method
145165
demos[demoMode]();
146-
166+
147167
display.setTextAlignment(TEXT_ALIGN_RIGHT);
148168
display.drawString(10, 128, String(millis()));
149169
// write the buffer to the display
@@ -156,4 +176,3 @@ void loop() {
156176
counter++;
157177
delay(10);
158178
}
159-

examples/SSD1306UiDemo/SSD1306UiDemo.ino

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,55 @@
2525
*/
2626

2727
#include <Wire.h>
28-
#include "SSD1306.h"
29-
#include "SSD1306Ui.h"
3028
#include "images.h"
3129

32-
// Initialize the OLED display on address 0x3c
33-
SSD1306 display(0x3c, D3, D4);
34-
SSD1306Ui ui ( &display );
30+
// Include the correct display library
31+
// For a connection via I2C using Wire include
32+
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
33+
// For a connection via I2C using brzo_i2c (must be installed) include
34+
// #include "SSD1306Brzo.h"
35+
// For a connection via SPI include
36+
// #include "SSD1306Spi.h"
3537

3638

37-
void msOverlay(SSD1306 *display, SSD1306UiState* state) {
39+
// Include the UI lib
40+
#include "OLEDDisplayUi.h"
41+
42+
// Use the corresponding display class:
43+
44+
// Initialize the OLED display using SPI
45+
// D5 -> SCL
46+
// D7 -> SDA
47+
// D0 -> RES
48+
// D2 -> DC
49+
// D8 -> CS
50+
// SSD1306Spi display(D0, D2, D8);
51+
52+
// Initialize the OLED display using brzo_i2c
53+
// D3 -> SDA
54+
// D4 -> SCL
55+
// SSD1306Brzo display(0x3c, D3, D5);
56+
57+
// Initialize the OLED display using Wire library
58+
SSD1306 display(0x3c, D3, D5);
59+
60+
OLEDDisplayUi ui ( &display );
61+
62+
void msOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
3863
display->setTextAlignment(TEXT_ALIGN_RIGHT);
3964
display->setFont(ArialMT_Plain_10);
4065
display->drawString(128, 0, String(millis()));
4166
}
4267

43-
void drawFrame1(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
68+
void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
4469
// draw an xbm image.
4570
// Please note that everything that should be transitioned
4671
// needs to be drawn relative to x and y
4772

4873
display->drawXbm(x + 34, y + 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
4974
}
5075

51-
void drawFrame2(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
76+
void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
5277
// Demonstrates the 3 included default sizes. The fonts come from SSD1306Fonts.h file
5378
// Besides the default fonts there will be a program to convert TrueType fonts into this format
5479
display->setTextAlignment(TEXT_ALIGN_LEFT);
@@ -62,7 +87,7 @@ void drawFrame2(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
6287
display->drawString(0 + x, 34 + y, "Arial 24");
6388
}
6489

65-
void drawFrame3(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
90+
void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
6691
// Text alignment demo
6792
display->setFont(ArialMT_Plain_10);
6893

@@ -79,7 +104,7 @@ void drawFrame3(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
79104
display->drawString(128 + x, 33 + y, "Right aligned (128,33)");
80105
}
81106

82-
void drawFrame4(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
107+
void drawFrame4(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
83108
// Demo for drawStringMaxWidth:
84109
// with the third parameter you can define the width after which words will be wrapped.
85110
// Currently only spaces and "-" are allowed for wrapping
@@ -88,8 +113,8 @@ void drawFrame4(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
88113
display->drawStringMaxWidth(0 + x, 10 + y, 128, "Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore.");
89114
}
90115

91-
void drawFrame5(SSD1306 *display, SSD1306UiState* state, int16_t x, int16_t y) {
92-
116+
void drawFrame5(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
117+
93118
}
94119

95120
// This array keeps function pointers to all frames
@@ -139,9 +164,6 @@ void setup() {
139164

140165
display.flipScreenVertically();
141166

142-
143-
144-
145167
}
146168

147169

@@ -153,9 +175,5 @@ void loop() {
153175
// Don't do stuff if you are below your
154176
// time budget.
155177
delay(remainingTimeBudget);
156-
157178
}
158-
159-
160179
}
161-

0 commit comments

Comments
 (0)