Skip to content

Commit 9ff5460

Browse files
committed
Harmonize examples
- format - use SDA, SCL pins by default with explanation - fix rendering millis() in SimpleDemo
1 parent 5930c1c commit 9ff5460

File tree

6 files changed

+325
-326
lines changed

6 files changed

+325
-326
lines changed

examples/SSD1306ClockDemo/SSD1306ClockDemo.ino

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
11
/**
2-
* The MIT License (MIT)
3-
*
4-
* Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
5-
*
6-
* Permission is hereby granted, free of charge, to any person obtaining a copy
7-
* of this software and associated documentation files (the "Software"), to deal
8-
* in the Software without restriction, including without limitation the rights
9-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10-
* copies of the Software, and to permit persons to whom the Software is
11-
* furnished to do so, subject to the following conditions:
12-
*
13-
* The above copyright notice and this permission notice shall be included in all
14-
* copies or substantial portions of the Software.
15-
*
16-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
* SOFTWARE.
23-
*
24-
* ThingPulse invests considerable time and money to develop these open source libraries.
25-
* Please support us by buying our products (and not the clones) from
26-
* https://thingpulse.com
27-
*
28-
*/
2+
The MIT License (MIT)
293
4+
Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.
23+
24+
ThingPulse invests considerable time and money to develop these open source libraries.
25+
Please support us by buying our products (and not the clones) from
26+
https://thingpulse.com
27+
28+
*/
29+
30+
// Install https://github.com/PaulStoffregen/Time
3031
#include <TimeLib.h>
3132

3233
// Include the correct display library
@@ -69,21 +70,21 @@
6970
// SH1106Brzo display(0x3c, D3, D5);
7071

7172
// Initialize the OLED display using Wire library
72-
SSD1306Wire display(0x3c, D3, D5);
73-
// SH1106Wire display(0x3c, D3, D5);
73+
SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h e.g. https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pins_arduino.h
74+
// SH1106Wire display(0x3c, SDA, SCL);
7475

7576
OLEDDisplayUi ui ( &display );
7677

7778
int screenW = 128;
7879
int screenH = 64;
79-
int clockCenterX = screenW/2;
80-
int clockCenterY = ((screenH-16)/2)+16; // top yellow part is 16 px height
80+
int clockCenterX = screenW / 2;
81+
int clockCenterY = ((screenH - 16) / 2) + 16; // top yellow part is 16 px height
8182
int clockRadius = 23;
8283

8384
// utility function for digital clock display: prints leading 0
84-
String twoDigits(int digits){
85-
if(digits < 10) {
86-
String i = '0'+String(digits);
85+
String twoDigits(int digits) {
86+
if (digits < 10) {
87+
String i = '0' + String(digits);
8788
return i;
8889
}
8990
else {
@@ -96,15 +97,15 @@ void clockOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
9697
}
9798

9899
void analogClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
99-
// ui.disableIndicator();
100+
// ui.disableIndicator();
100101

101102
// Draw the clock face
102-
// display->drawCircle(clockCenterX + x, clockCenterY + y, clockRadius);
103+
// display->drawCircle(clockCenterX + x, clockCenterY + y, clockRadius);
103104
display->drawCircle(clockCenterX + x, clockCenterY + y, 2);
104105
//
105106
//hour ticks
106-
for( int z=0; z < 360;z= z + 30 ){
107-
//Begin at 0° and stop at 360°
107+
for ( int z = 0; z < 360; z = z + 30 ) {
108+
//Begin at 0° and stop at 360°
108109
float angle = z ;
109110
angle = ( angle / 57.29577951 ) ; //Convert degrees to radians
110111
int x2 = ( clockCenterX + ( sin(angle) * clockRadius ) );
@@ -137,7 +138,7 @@ void analogClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x
137138
}
138139

139140
void digitalClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
140-
String timenow = String(hour())+":"+twoDigits(minute())+":"+twoDigits(second());
141+
String timenow = String(hour()) + ":" + twoDigits(minute()) + ":" + twoDigits(second());
141142
display->setTextAlignment(TEXT_ALIGN_CENTER);
142143
display->setFont(ArialMT_Plain_24);
143144
display->drawString(clockCenterX + x , clockCenterY + y, timenow );
@@ -155,15 +156,15 @@ OverlayCallback overlays[] = { clockOverlay };
155156
int overlaysCount = 1;
156157

157158
void setup() {
158-
Serial.begin(9600);
159+
Serial.begin(115200);
159160
Serial.println();
160161

161-
// The ESP is capable of rendering 60fps in 80Mhz mode
162-
// but that won't give you much time for anything else
163-
// run it in 160Mhz mode or just set it to 30 fps
162+
// The ESP is capable of rendering 60fps in 80Mhz mode
163+
// but that won't give you much time for anything else
164+
// run it in 160Mhz mode or just set it to 30 fps
164165
ui.setTargetFPS(60);
165166

166-
// Customize the active and inactive symbol
167+
// Customize the active and inactive symbol
167168
ui.setActiveSymbol(activeSymbol);
168169
ui.setInactiveSymbol(inactiveSymbol);
169170

@@ -207,8 +208,5 @@ void loop() {
207208
// Don't do stuff if you are below your
208209
// time budget.
209210
delay(remainingTimeBudget);
210-
211211
}
212-
213-
214212
}

0 commit comments

Comments
 (0)