Skip to content

Commit 373eff3

Browse files
authored
Merge pull request #72 from squix78/add-samples
Add sample code
2 parents 4cc711e + 19a0787 commit 373eff3

File tree

3 files changed

+334
-0
lines changed

3 files changed

+334
-0
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ cache:
1111
env:
1212
- PLATFORMIO_CI_SRC=examples/SSD1306UiDemo
1313
- PLATFORMIO_CI_SRC=examples/SSD1306SimpleDemo
14+
- PLATFORMIO_CI_SRC=examples/SSD1306DrawingDemo
15+
- PLATFORMIO_CI_SRC=examples/SSD1306OTADemo
1416
- PLATFORMIO_CI_SRC=examples/SSD1306ClockDemo
1517

1618

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016 by Daniel Eichhorn
5+
* Copyright (c) 2016 by Fabrice Weinberg
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*
25+
*/
26+
27+
// Include the correct display library
28+
// For a connection via I2C using Wire include
29+
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
30+
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
31+
// For a connection via I2C using brzo_i2c (must be installed) include
32+
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
33+
// #include "SSD1306Brzo.h"
34+
// For a connection via SPI include
35+
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
36+
// #include "SSD1306Spi.h"
37+
38+
// Use the corresponding display class:
39+
40+
// Initialize the OLED display using SPI
41+
// D5 -> CLK
42+
// D7 -> MOSI (DOUT)
43+
// D0 -> RES
44+
// D2 -> DC
45+
// D8 -> CS
46+
// SSD1306Spi display(D0, D2, D8);
47+
48+
// Initialize the OLED display using brzo_i2c
49+
// D3 -> SDA
50+
// D4 -> SCL
51+
// SSD1306Brzo display(0x3c, D3, D5);
52+
53+
// Initialize the OLED display using Wire library
54+
SSD1306 display(0x3c, D3, D5);
55+
56+
// Adapted from Adafruit_SSD1306
57+
void drawLines() {
58+
for (int16_t i=0; i<DISPLAY_WIDTH; i+=4) {
59+
display.drawLine(0, 0, i, DISPLAY_HEIGHT-1);
60+
display.display();
61+
delay(10);
62+
}
63+
for (int16_t i=0; i<DISPLAY_HEIGHT; i+=4) {
64+
display.drawLine(0, 0, DISPLAY_WIDTH-1, i);
65+
display.display();
66+
delay(10);
67+
}
68+
delay(250);
69+
70+
display.clear();
71+
for (int16_t i=0; i<DISPLAY_WIDTH; i+=4) {
72+
display.drawLine(0, DISPLAY_HEIGHT-1, i, 0);
73+
display.display();
74+
delay(10);
75+
}
76+
for (int16_t i=DISPLAY_HEIGHT-1; i>=0; i-=4) {
77+
display.drawLine(0, DISPLAY_HEIGHT-1, DISPLAY_WIDTH-1, i);
78+
display.display();
79+
delay(10);
80+
}
81+
delay(250);
82+
83+
display.clear();
84+
for (int16_t i=DISPLAY_WIDTH-1; i>=0; i-=4) {
85+
display.drawLine(DISPLAY_WIDTH-1, DISPLAY_HEIGHT-1, i, 0);
86+
display.display();
87+
delay(10);
88+
}
89+
for (int16_t i=DISPLAY_HEIGHT-1; i>=0; i-=4) {
90+
display.drawLine(DISPLAY_WIDTH-1, DISPLAY_HEIGHT-1, 0, i);
91+
display.display();
92+
delay(10);
93+
}
94+
delay(250);
95+
display.clear();
96+
for (int16_t i=0; i<DISPLAY_HEIGHT; i+=4) {
97+
display.drawLine(DISPLAY_WIDTH-1, 0, 0, i);
98+
display.display();
99+
delay(10);
100+
}
101+
for (int16_t i=0; i<DISPLAY_WIDTH; i+=4) {
102+
display.drawLine(DISPLAY_WIDTH-1, 0, i, DISPLAY_HEIGHT-1);
103+
display.display();
104+
delay(10);
105+
}
106+
delay(250);
107+
}
108+
109+
// Adapted from Adafruit_SSD1306
110+
void drawRect(void) {
111+
for (int16_t i=0; i<DISPLAY_HEIGHT/2; i+=2) {
112+
display.drawRect(i, i, DISPLAY_WIDTH-2*i, DISPLAY_HEIGHT-2*i);
113+
display.display();
114+
delay(10);
115+
}
116+
}
117+
118+
// Adapted from Adafruit_SSD1306
119+
void fillRect(void) {
120+
uint8_t color = 1;
121+
for (int16_t i=0; i<DISPLAY_HEIGHT/2; i+=3) {
122+
display.setColor((color % 2 == 0) ? BLACK : WHITE); // alternate colors
123+
display.fillRect(i, i, DISPLAY_WIDTH - i*2, DISPLAY_HEIGHT - i*2);
124+
display.display();
125+
delay(10);
126+
color++;
127+
}
128+
// Reset back to WHITE
129+
display.setColor(WHITE);
130+
}
131+
132+
// Adapted from Adafruit_SSD1306
133+
void drawCircle(void) {
134+
for (int16_t i=0; i<DISPLAY_HEIGHT; i+=2) {
135+
display.drawCircle(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, i);
136+
display.display();
137+
delay(10);
138+
}
139+
delay(1000);
140+
display.clear();
141+
142+
// This will draw the part of the circel in quadrant 1
143+
// Quadrants are numberd like this:
144+
// 0010 | 0001
145+
// ------|-----
146+
// 0100 | 1000
147+
//
148+
display.drawCircleQuads(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, DISPLAY_HEIGHT/4, 0b00000001);
149+
display.display();
150+
delay(200);
151+
display.drawCircleQuads(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, DISPLAY_HEIGHT/4, 0b00000011);
152+
display.display();
153+
delay(200);
154+
display.drawCircleQuads(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, DISPLAY_HEIGHT/4, 0b00000111);
155+
display.display();
156+
delay(200);
157+
display.drawCircleQuads(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, DISPLAY_HEIGHT/4, 0b00001111);
158+
display.display();
159+
}
160+
161+
void printBuffer(void) {
162+
// Initialize the log buffer
163+
// allocate memory to store 8 lines of text and 30 chars per line.
164+
display.setLogBuffer(5, 30);
165+
166+
// Some test data
167+
const char* test[] = {
168+
"Hello",
169+
"World" ,
170+
"----",
171+
"Show off",
172+
"how",
173+
"the log buffer",
174+
"is",
175+
"working.",
176+
"Even",
177+
"scrolling is",
178+
"working"
179+
};
180+
181+
for (uint8_t i = 0; i < 11; i++) {
182+
display.clear();
183+
// Print to the screen
184+
display.println(test[i]);
185+
// Draw it to the internal screen buffer
186+
display.drawLogBuffer(0, 0);
187+
// Display it on the screen
188+
display.display();
189+
delay(500);
190+
}
191+
}
192+
193+
void setup() {
194+
display.init();
195+
196+
// display.flipScreenVertically();
197+
198+
display.setContrast(255);
199+
200+
drawLines();
201+
delay(1000);
202+
display.clear();
203+
204+
drawRect();
205+
delay(1000);
206+
display.clear();
207+
208+
fillRect();
209+
delay(1000);
210+
display.clear();
211+
212+
drawCircle();
213+
delay(1000);
214+
display.clear();
215+
216+
printBuffer();
217+
delay(1000);
218+
display.clear();
219+
}
220+
221+
void loop() { }
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/**
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2016 by Daniel Eichhorn
5+
* Copyright (c) 2016 by Fabrice Weinberg
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in all
15+
* copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
* SOFTWARE.
24+
*
25+
*/
26+
27+
// WiFi includes
28+
#include <ESP8266WiFi.h>
29+
30+
// OTA Includes
31+
#include <ESP8266mDNS.h>
32+
#include <ArduinoOTA.h>
33+
34+
const char *ssid = "[Your SSID]";
35+
const char *password = "[Your Password]";
36+
37+
38+
// Include the correct display library
39+
// For a connection via I2C using Wire include
40+
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
41+
#include "SSD1306.h" // alias for `#include "SSD1306Wire.h"`
42+
// For a connection via I2C using brzo_i2c (must be installed) include
43+
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
44+
// #include "SSD1306Brzo.h"
45+
// For a connection via SPI include
46+
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
47+
// #include "SSD1306Spi.h"
48+
49+
// Use the corresponding display class:
50+
51+
// Initialize the OLED display using SPI
52+
// D5 -> CLK
53+
// D7 -> MOSI (DOUT)
54+
// D0 -> RES
55+
// D2 -> DC
56+
// D8 -> CS
57+
// SSD1306Spi display(D0, D2, D8);
58+
59+
// Initialize the OLED display using brzo_i2c
60+
// D3 -> SDA
61+
// D4 -> SCL
62+
// SSD1306Brzo display(0x3c, D3, D5);
63+
64+
// Initialize the OLED display using Wire library
65+
SSD1306 display(0x3c, D3, D5);
66+
67+
68+
void setup() {
69+
WiFi.begin ( ssid, password );
70+
71+
// Wait for connection
72+
while ( WiFi.status() != WL_CONNECTED ) {
73+
delay ( 10 );
74+
}
75+
76+
display.init();
77+
display.flipScreenVertically();
78+
display.setContrast(255);
79+
80+
ArduinoOTA.begin();
81+
ArduinoOTA.onStart([]() {
82+
display.clear();
83+
display.setFont(ArialMT_Plain_10);
84+
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
85+
display.drawString(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2 - 10, "OTA Update");
86+
display.display();
87+
});
88+
89+
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
90+
display.drawProgressBar(4, 32, 120, 8, progress / (total / 100) );
91+
display.display();
92+
});
93+
94+
ArduinoOTA.onEnd([]() {
95+
display.clear();
96+
display.setFont(ArialMT_Plain_10);
97+
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
98+
display.drawString(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, "Restart");
99+
display.display();
100+
});
101+
102+
// Align text vertical/horizontal center
103+
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
104+
display.setFont(ArialMT_Plain_10);
105+
display.drawString(DISPLAY_WIDTH/2, DISPLAY_HEIGHT/2, "Ready for OTA:\n" + WiFi.localIP().toString());
106+
display.display();
107+
}
108+
109+
void loop() {
110+
ArduinoOTA.handle();
111+
}

0 commit comments

Comments
 (0)