Prvni odevzdani
This commit is contained in:
214
examples/SSD1306ClockDemo/SSD1306ClockDemo.ino
Normal file
214
examples/SSD1306ClockDemo/SSD1306ClockDemo.ino
Normal file
@ -0,0 +1,214 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* ThingPulse invests considerable time and money to develop these open source libraries.
|
||||
* Please support us by buying our products (and not the clones) from
|
||||
* https://thingpulse.com
|
||||
*
|
||||
*/
|
||||
|
||||
#include <TimeLib.h>
|
||||
|
||||
// Include the correct display library
|
||||
// For a connection via I2C using Wire include
|
||||
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
|
||||
// or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"`
|
||||
// For a connection via I2C using brzo_i2c (must be installed) include
|
||||
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Brzo.h"
|
||||
// #include "SH1106Brzo.h"
|
||||
// For a connection via SPI include
|
||||
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Spi.h"
|
||||
// #include "SH1106SPi.h"
|
||||
|
||||
// Include the UI lib
|
||||
#include "OLEDDisplayUi.h"
|
||||
|
||||
// Include custom images
|
||||
#include "images.h"
|
||||
|
||||
// Use the corresponding display class:
|
||||
|
||||
// Initialize the OLED display using SPI
|
||||
// D5 -> CLK
|
||||
// D7 -> MOSI (DOUT)
|
||||
// D0 -> RES
|
||||
// D2 -> DC
|
||||
// D8 -> CS
|
||||
// SSD1306Spi display(D0, D2, D8);
|
||||
// or
|
||||
// SH1106Spi display(D0, D2);
|
||||
|
||||
// Initialize the OLED display using brzo_i2c
|
||||
// D3 -> SDA
|
||||
// D5 -> SCL
|
||||
// SSD1306Brzo display(0x3c, D3, D5);
|
||||
// or
|
||||
// SH1106Brzo display(0x3c, D3, D5);
|
||||
|
||||
// Initialize the OLED display using Wire library
|
||||
SSD1306Wire display(0x3c, D3, D5);
|
||||
// SH1106 display(0x3c, D3, D5);
|
||||
|
||||
OLEDDisplayUi ui ( &display );
|
||||
|
||||
int screenW = 128;
|
||||
int screenH = 64;
|
||||
int clockCenterX = screenW/2;
|
||||
int clockCenterY = ((screenH-16)/2)+16; // top yellow part is 16 px height
|
||||
int clockRadius = 23;
|
||||
|
||||
// utility function for digital clock display: prints leading 0
|
||||
String twoDigits(int digits){
|
||||
if(digits < 10) {
|
||||
String i = '0'+String(digits);
|
||||
return i;
|
||||
}
|
||||
else {
|
||||
return String(digits);
|
||||
}
|
||||
}
|
||||
|
||||
void clockOverlay(OLEDDisplay *display, OLEDDisplayUiState* state) {
|
||||
|
||||
}
|
||||
|
||||
void analogClockFrame(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
|
||||
// ui.disableIndicator();
|
||||
|
||||
// Draw the clock face
|
||||
// display->drawCircle(clockCenterX + x, clockCenterY + y, clockRadius);
|
||||
display->drawCircle(clockCenterX + x, clockCenterY + y, 2);
|
||||
//
|
||||
//hour ticks
|
||||
for( int z=0; z < 360;z= z + 30 ){
|
||||
//Begin at 0° and stop at 360°
|
||||
float angle = z ;
|
||||
angle = ( angle / 57.29577951 ) ; //Convert degrees to radians
|
||||
int x2 = ( clockCenterX + ( sin(angle) * clockRadius ) );
|
||||
int y2 = ( clockCenterY - ( cos(angle) * clockRadius ) );
|
||||
int x3 = ( clockCenterX + ( sin(angle) * ( clockRadius - ( clockRadius / 8 ) ) ) );
|
||||
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
|
||||
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
|
||||
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
|
||||
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(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);
|
||||
display->drawString(clockCenterX + x , clockCenterY + y, timenow );
|
||||
}
|
||||
|
||||
// This array keeps function pointers to all frames
|
||||
// frames are the single views that slide in
|
||||
FrameCallback frames[] = { analogClockFrame, digitalClockFrame };
|
||||
|
||||
// how many frames are there?
|
||||
int frameCount = 2;
|
||||
|
||||
// Overlays are statically drawn on top of a frame eg. a clock
|
||||
OverlayCallback overlays[] = { clockOverlay };
|
||||
int overlaysCount = 1;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println();
|
||||
|
||||
// The ESP is capable of rendering 60fps in 80Mhz mode
|
||||
// but that won't give you much time for anything else
|
||||
// run it in 160Mhz mode or just set it to 30 fps
|
||||
ui.setTargetFPS(60);
|
||||
|
||||
// Customize the active and inactive symbol
|
||||
ui.setActiveSymbol(activeSymbol);
|
||||
ui.setInactiveSymbol(inactiveSymbol);
|
||||
|
||||
// You can change this to
|
||||
// TOP, LEFT, BOTTOM, RIGHT
|
||||
ui.setIndicatorPosition(TOP);
|
||||
|
||||
// Defines where the first frame is located in the bar.
|
||||
ui.setIndicatorDirection(LEFT_RIGHT);
|
||||
|
||||
// You can change the transition that is used
|
||||
// SLIDE_LEFT, SLIDE_RIGHT, SLIDE_UP, SLIDE_DOWN
|
||||
ui.setFrameAnimation(SLIDE_LEFT);
|
||||
|
||||
// Add frames
|
||||
ui.setFrames(frames, frameCount);
|
||||
|
||||
// Add overlays
|
||||
ui.setOverlays(overlays, overlaysCount);
|
||||
|
||||
// Initialising the UI will init the display too.
|
||||
ui.init();
|
||||
|
||||
display.flipScreenVertically();
|
||||
|
||||
unsigned long secsSinceStart = millis();
|
||||
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
|
||||
const unsigned long seventyYears = 2208988800UL;
|
||||
// subtract seventy years:
|
||||
unsigned long epoch = secsSinceStart - seventyYears * SECS_PER_HOUR;
|
||||
setTime(epoch);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
int remainingTimeBudget = ui.update();
|
||||
|
||||
if (remainingTimeBudget > 0) {
|
||||
// You can do some work here
|
||||
// Don't do stuff if you are below your
|
||||
// time budget.
|
||||
delay(remainingTimeBudget);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
21
examples/SSD1306ClockDemo/images.h
Normal file
21
examples/SSD1306ClockDemo/images.h
Normal file
@ -0,0 +1,21 @@
|
||||
const unsigned char activeSymbol[] PROGMEM = {
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00011000,
|
||||
B00100100,
|
||||
B01000010,
|
||||
B01000010,
|
||||
B00100100,
|
||||
B00011000
|
||||
};
|
||||
|
||||
const unsigned char inactiveSymbol[] PROGMEM = {
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00011000,
|
||||
B00011000,
|
||||
B00000000,
|
||||
B00000000
|
||||
};
|
233
examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino
Normal file
233
examples/SSD1306DrawingDemo/SSD1306DrawingDemo.ino
Normal file
@ -0,0 +1,233 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
|
||||
* Copyright (c) 2018 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* ThingPulse invests considerable time and money to develop these open source libraries.
|
||||
* Please support us by buying our products (and not the clones) from
|
||||
* https://thingpulse.com
|
||||
*
|
||||
*/
|
||||
|
||||
// Include the correct display library
|
||||
// For a connection via I2C using Wire include
|
||||
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
|
||||
// or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"`
|
||||
// For a connection via I2C using brzo_i2c (must be installed) include
|
||||
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Brzo.h"
|
||||
// #include "SH1106Brzo.h"
|
||||
// For a connection via SPI include
|
||||
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Spi.h"
|
||||
// #include "SH1106SPi.h"
|
||||
|
||||
// Use the corresponding display class:
|
||||
|
||||
// Initialize the OLED display using SPI
|
||||
// D5 -> CLK
|
||||
// D7 -> MOSI (DOUT)
|
||||
// D0 -> RES
|
||||
// D2 -> DC
|
||||
// D8 -> CS
|
||||
// SSD1306Spi display(D0, D2, D8);
|
||||
// or
|
||||
// SH1106Spi display(D0, D2);
|
||||
|
||||
// Initialize the OLED display using brzo_i2c
|
||||
// D3 -> SDA
|
||||
// D5 -> SCL
|
||||
// SSD1306Brzo display(0x3c, D3, D5);
|
||||
// or
|
||||
// SH1106Brzo display(0x3c, D3, D5);
|
||||
|
||||
// Initialize the OLED display using Wire library
|
||||
SSD1306Wire display(0x3c, D3, D5);
|
||||
// SH1106 display(0x3c, D3, D5);
|
||||
|
||||
// Adapted from Adafruit_SSD1306
|
||||
void drawLines() {
|
||||
for (int16_t i=0; i<display.getWidth(); i+=4) {
|
||||
display.drawLine(0, 0, i, display.getHeight()-1);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
for (int16_t i=0; i<display.getHeight(); i+=4) {
|
||||
display.drawLine(0, 0, display.getWidth()-1, i);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clear();
|
||||
for (int16_t i=0; i<display.getWidth(); i+=4) {
|
||||
display.drawLine(0, display.getHeight()-1, i, 0);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
for (int16_t i=display.getHeight()-1; i>=0; i-=4) {
|
||||
display.drawLine(0, display.getHeight()-1, display.getWidth()-1, i);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clear();
|
||||
for (int16_t i=display.getWidth()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.getWidth()-1, display.getHeight()-1, i, 0);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
for (int16_t i=display.getHeight()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.getWidth()-1, display.getHeight()-1, 0, i);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
delay(250);
|
||||
display.clear();
|
||||
for (int16_t i=0; i<display.getHeight(); i+=4) {
|
||||
display.drawLine(display.getWidth()-1, 0, 0, i);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
for (int16_t i=0; i<display.getWidth(); i+=4) {
|
||||
display.drawLine(display.getWidth()-1, 0, i, display.getHeight()-1);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
|
||||
// Adapted from Adafruit_SSD1306
|
||||
void drawRect(void) {
|
||||
for (int16_t i=0; i<display.getHeight()/2; i+=2) {
|
||||
display.drawRect(i, i, display.getWidth()-2*i, display.getHeight()-2*i);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
}
|
||||
|
||||
// Adapted from Adafruit_SSD1306
|
||||
void fillRect(void) {
|
||||
uint8_t color = 1;
|
||||
for (int16_t i=0; i<display.getHeight()/2; i+=3) {
|
||||
display.setColor((color % 2 == 0) ? BLACK : WHITE); // alternate colors
|
||||
display.fillRect(i, i, display.getWidth() - i*2, display.getHeight() - i*2);
|
||||
display.display();
|
||||
delay(10);
|
||||
color++;
|
||||
}
|
||||
// Reset back to WHITE
|
||||
display.setColor(WHITE);
|
||||
}
|
||||
|
||||
// Adapted from Adafruit_SSD1306
|
||||
void drawCircle(void) {
|
||||
for (int16_t i=0; i<display.getHeight(); i+=2) {
|
||||
display.drawCircle(display.getWidth()/2, display.getHeight()/2, i);
|
||||
display.display();
|
||||
delay(10);
|
||||
}
|
||||
delay(1000);
|
||||
display.clear();
|
||||
|
||||
// This will draw the part of the circel in quadrant 1
|
||||
// Quadrants are numberd like this:
|
||||
// 0010 | 0001
|
||||
// ------|-----
|
||||
// 0100 | 1000
|
||||
//
|
||||
display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00000001);
|
||||
display.display();
|
||||
delay(200);
|
||||
display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00000011);
|
||||
display.display();
|
||||
delay(200);
|
||||
display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00000111);
|
||||
display.display();
|
||||
delay(200);
|
||||
display.drawCircleQuads(display.getWidth()/2, display.getHeight()/2, display.getHeight()/4, 0b00001111);
|
||||
display.display();
|
||||
}
|
||||
|
||||
void printBuffer(void) {
|
||||
// Initialize the log buffer
|
||||
// allocate memory to store 8 lines of text and 30 chars per line.
|
||||
display.setLogBuffer(5, 30);
|
||||
|
||||
// Some test data
|
||||
const char* test[] = {
|
||||
"Hello",
|
||||
"World" ,
|
||||
"----",
|
||||
"Show off",
|
||||
"how",
|
||||
"the log buffer",
|
||||
"is",
|
||||
"working.",
|
||||
"Even",
|
||||
"scrolling is",
|
||||
"working"
|
||||
};
|
||||
|
||||
for (uint8_t i = 0; i < 11; i++) {
|
||||
display.clear();
|
||||
// Print to the screen
|
||||
display.println(test[i]);
|
||||
// Draw it to the internal screen buffer
|
||||
display.drawLogBuffer(0, 0);
|
||||
// Display it on the screen
|
||||
display.display();
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
display.init();
|
||||
|
||||
// display.flipScreenVertically();
|
||||
|
||||
display.setContrast(255);
|
||||
|
||||
drawLines();
|
||||
delay(1000);
|
||||
display.clear();
|
||||
|
||||
drawRect();
|
||||
delay(1000);
|
||||
display.clear();
|
||||
|
||||
fillRect();
|
||||
delay(1000);
|
||||
display.clear();
|
||||
|
||||
drawCircle();
|
||||
delay(1000);
|
||||
display.clear();
|
||||
|
||||
printBuffer();
|
||||
delay(1000);
|
||||
display.clear();
|
||||
}
|
||||
|
||||
void loop() { }
|
123
examples/SSD1306OTADemo/SSD1306OTADemo.ino
Normal file
123
examples/SSD1306OTADemo/SSD1306OTADemo.ino
Normal file
@ -0,0 +1,123 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
|
||||
* Copyright (c) 2018 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* ThingPulse invests considerable time and money to develop these open source libraries.
|
||||
* Please support us by buying our products (and not the clones) from
|
||||
* https://thingpulse.com
|
||||
*
|
||||
*/
|
||||
|
||||
// WiFi includes
|
||||
#include <ESP8266WiFi.h>
|
||||
|
||||
// OTA Includes
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <ArduinoOTA.h>
|
||||
|
||||
const char *ssid = "[Your SSID]";
|
||||
const char *password = "[Your Password]";
|
||||
|
||||
|
||||
// Include the correct display library
|
||||
// For a connection via I2C using Wire include
|
||||
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
|
||||
// or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"`
|
||||
// For a connection via I2C using brzo_i2c (must be installed) include
|
||||
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Brzo.h"
|
||||
// #include "SH1106Brzo.h"
|
||||
// For a connection via SPI include
|
||||
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Spi.h"
|
||||
// #include "SH1106SPi.h"
|
||||
|
||||
// Use the corresponding display class:
|
||||
|
||||
// Initialize the OLED display using SPI
|
||||
// D5 -> CLK
|
||||
// D7 -> MOSI (DOUT)
|
||||
// D0 -> RES
|
||||
// D2 -> DC
|
||||
// D8 -> CS
|
||||
// SSD1306Spi display(D0, D2, D8);
|
||||
// or
|
||||
// SH1106Spi display(D0, D2);
|
||||
|
||||
// Initialize the OLED display using brzo_i2c
|
||||
// D3 -> SDA
|
||||
// D5 -> SCL
|
||||
// SSD1306Brzo display(0x3c, D3, D5);
|
||||
// or
|
||||
// SH1106Brzo display(0x3c, D3, D5);
|
||||
|
||||
// Initialize the OLED display using Wire library
|
||||
SSD1306Wire display(0x3c, D3, D5);
|
||||
// SH1106 display(0x3c, D3, D5);
|
||||
|
||||
|
||||
void setup() {
|
||||
WiFi.begin ( ssid, password );
|
||||
|
||||
// Wait for connection
|
||||
while ( WiFi.status() != WL_CONNECTED ) {
|
||||
delay ( 10 );
|
||||
}
|
||||
|
||||
display.init();
|
||||
display.flipScreenVertically();
|
||||
display.setContrast(255);
|
||||
|
||||
ArduinoOTA.begin();
|
||||
ArduinoOTA.onStart([]() {
|
||||
display.clear();
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
|
||||
display.drawString(display.getWidth()/2, display.getHeight()/2 - 10, "OTA Update");
|
||||
display.display();
|
||||
});
|
||||
|
||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
||||
display.drawProgressBar(4, 32, 120, 8, progress / (total / 100) );
|
||||
display.display();
|
||||
});
|
||||
|
||||
ArduinoOTA.onEnd([]() {
|
||||
display.clear();
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
|
||||
display.drawString(display.getWidth()/2, display.getHeight()/2, "Restart");
|
||||
display.display();
|
||||
});
|
||||
|
||||
// Align text vertical/horizontal center
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER_BOTH);
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.drawString(display.getWidth()/2, display.getHeight()/2, "Ready for OTA:\n" + WiFi.localIP().toString());
|
||||
display.display();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
ArduinoOTA.handle();
|
||||
}
|
197
examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino
Normal file
197
examples/SSD1306SimpleDemo/SSD1306SimpleDemo.ino
Normal file
@ -0,0 +1,197 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
|
||||
* Copyright (c) 2018 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* ThingPulse invests considerable time and money to develop these open source libraries.
|
||||
* Please support us by buying our products (and not the clones) from
|
||||
* https://thingpulse.com
|
||||
*
|
||||
*/
|
||||
|
||||
// Include the correct display library
|
||||
|
||||
// For a connection via I2C using the Arduino Wire include:
|
||||
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
#include "SSD1306Wire.h" // legacy: #include "SSD1306.h"
|
||||
// OR #include "SH1106Wire.h" // legacy: #include "SH1106.h"
|
||||
|
||||
// For a connection via I2C using brzo_i2c (must be installed) include:
|
||||
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Brzo.h"
|
||||
// OR #include "SH1106Brzo.h"
|
||||
|
||||
// For a connection via SPI include:
|
||||
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Spi.h"
|
||||
// OR #include "SH1106SPi.h"
|
||||
|
||||
|
||||
// Optionally include custom images
|
||||
#include "images.h"
|
||||
|
||||
|
||||
// Initialize the OLED display using Arduino Wire:
|
||||
SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL - SDA and SCL usually populate automatically based on your board's pins_arduino.h
|
||||
// SSD1306Wire display(0x3c, D3, D5); // ADDRESS, SDA, SCL - If not, they can be specified manually.
|
||||
// SSD1306Wire display(0x3c, SDA, SCL, GEOMETRY_128_32); // ADDRESS, SDA, SCL, OLEDDISPLAY_GEOMETRY - Extra param required for 128x32 displays.
|
||||
// SH1106 display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL
|
||||
|
||||
// Initialize the OLED display using brzo_i2c:
|
||||
// SSD1306Brzo display(0x3c, D3, D5); // ADDRESS, SDA, SCL
|
||||
// or
|
||||
// SH1106Brzo display(0x3c, D3, D5); // ADDRESS, SDA, SCL
|
||||
|
||||
// Initialize the OLED display using SPI:
|
||||
// D5 -> CLK
|
||||
// D7 -> MOSI (DOUT)
|
||||
// D0 -> RES
|
||||
// D2 -> DC
|
||||
// D8 -> CS
|
||||
// SSD1306Spi display(D0, D2, D8); // RES, DC, CS
|
||||
// or
|
||||
// SH1106Spi display(D0, D2); // RES, DC
|
||||
|
||||
|
||||
#define DEMO_DURATION 3000
|
||||
typedef void (*Demo)(void);
|
||||
|
||||
int demoMode = 0;
|
||||
int counter = 1;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
|
||||
// Initialising the UI will init the display too.
|
||||
display.init();
|
||||
|
||||
display.flipScreenVertically();
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
|
||||
}
|
||||
|
||||
void drawFontFaceDemo() {
|
||||
// Font Demo1
|
||||
// create more fonts at http://oleddisplay.squix.ch/
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.drawString(0, 0, "Hello world");
|
||||
display.setFont(ArialMT_Plain_16);
|
||||
display.drawString(0, 10, "Hello world");
|
||||
display.setFont(ArialMT_Plain_24);
|
||||
display.drawString(0, 26, "Hello world");
|
||||
}
|
||||
|
||||
void drawTextFlowDemo() {
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawStringMaxWidth(0, 0, 128,
|
||||
"Lorem ipsum\n dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore." );
|
||||
}
|
||||
|
||||
void drawTextAlignmentDemo() {
|
||||
// Text alignment demo
|
||||
display.setFont(ArialMT_Plain_10);
|
||||
|
||||
// The coordinates define the left starting point of the text
|
||||
display.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display.drawString(0, 10, "Left aligned (0,10)");
|
||||
|
||||
// The coordinates define the center of the text
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display.drawString(64, 22, "Center aligned (64,22)");
|
||||
|
||||
// The coordinates define the right end of the text
|
||||
display.setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display.drawString(128, 33, "Right aligned (128,33)");
|
||||
}
|
||||
|
||||
void drawRectDemo() {
|
||||
// Draw a pixel at given position
|
||||
for (int i = 0; i < 10; i++) {
|
||||
display.setPixel(i, i);
|
||||
display.setPixel(10 - i, i);
|
||||
}
|
||||
display.drawRect(12, 12, 20, 20);
|
||||
|
||||
// Fill the rectangle
|
||||
display.fillRect(14, 14, 17, 17);
|
||||
|
||||
// Draw a line horizontally
|
||||
display.drawHorizontalLine(0, 40, 20);
|
||||
|
||||
// Draw a line horizontally
|
||||
display.drawVerticalLine(40, 0, 20);
|
||||
}
|
||||
|
||||
void drawCircleDemo() {
|
||||
for (int i=1; i < 8; i++) {
|
||||
display.setColor(WHITE);
|
||||
display.drawCircle(32, 32, i*3);
|
||||
if (i % 2 == 0) {
|
||||
display.setColor(BLACK);
|
||||
}
|
||||
display.fillCircle(96, 32, 32 - i* 3);
|
||||
}
|
||||
}
|
||||
|
||||
void drawProgressBarDemo() {
|
||||
int progress = (counter / 5) % 100;
|
||||
// draw the progress bar
|
||||
display.drawProgressBar(0, 32, 120, 10, progress);
|
||||
|
||||
// draw the percentage as String
|
||||
display.setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display.drawString(64, 15, String(progress) + "%");
|
||||
}
|
||||
|
||||
void drawImageDemo() {
|
||||
// see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-create-xbm.html
|
||||
// on how to create xbm files
|
||||
display.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() {
|
||||
// clear the display
|
||||
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
|
||||
display.display();
|
||||
|
||||
if (millis() - timeSinceLastModeSwitch > DEMO_DURATION) {
|
||||
demoMode = (demoMode + 1) % demoLength;
|
||||
timeSinceLastModeSwitch = millis();
|
||||
}
|
||||
counter++;
|
||||
delay(10);
|
||||
}
|
28
examples/SSD1306SimpleDemo/images.h
Normal file
28
examples/SSD1306SimpleDemo/images.h
Normal file
@ -0,0 +1,28 @@
|
||||
#define WiFi_Logo_width 60
|
||||
#define WiFi_Logo_height 36
|
||||
const uint8_t WiFi_Logo_bits[] PROGMEM = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
|
||||
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
|
||||
0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF,
|
||||
0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00,
|
||||
0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C,
|
||||
0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00,
|
||||
0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C,
|
||||
0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00,
|
||||
0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C,
|
||||
0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00,
|
||||
0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C,
|
||||
0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00,
|
||||
0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F,
|
||||
0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00,
|
||||
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF,
|
||||
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
|
||||
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
75
examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino
Normal file
75
examples/SSD1306TwoScreenDemo/SSD1306TwoScreenDemo.ino
Normal file
@ -0,0 +1,75 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* ThingPulse invests considerable time and money to develop these open source libraries.
|
||||
* Please support us by buying our products (and not the clones) from
|
||||
* https://thingpulse.com
|
||||
*
|
||||
*/
|
||||
|
||||
// Include the correct display library
|
||||
// For a connection via I2C using Wire include
|
||||
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
|
||||
#include "images.h"
|
||||
|
||||
// Initialize the OLED display using Wire library
|
||||
SSD1306Wire display(0x3c, D3, D5);
|
||||
SSD1306Wire display2(0x3c, D1, D2);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
|
||||
// Initialising the UI will init the display too.
|
||||
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);
|
||||
|
||||
display2.flipScreenVertically();
|
||||
display2.setFont(ArialMT_Plain_10);
|
||||
display2.setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
display.clear();
|
||||
display.drawString(0, 0, "Hello world: " + String(millis()));
|
||||
display.display();
|
||||
|
||||
display2.clear();
|
||||
display2.drawString(0, 0, "Hello world: " + String(millis()));
|
||||
display2.display();
|
||||
|
||||
delay(10);
|
||||
}
|
28
examples/SSD1306TwoScreenDemo/images.h
Normal file
28
examples/SSD1306TwoScreenDemo/images.h
Normal file
@ -0,0 +1,28 @@
|
||||
#define WiFi_Logo_width 60
|
||||
#define WiFi_Logo_height 36
|
||||
const uint8_t WiFi_Logo_bits[] PROGMEM = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
|
||||
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
|
||||
0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF,
|
||||
0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00,
|
||||
0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C,
|
||||
0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00,
|
||||
0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C,
|
||||
0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00,
|
||||
0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C,
|
||||
0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00,
|
||||
0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C,
|
||||
0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00,
|
||||
0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F,
|
||||
0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00,
|
||||
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF,
|
||||
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
|
||||
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
194
examples/SSD1306UiDemo/SSD1306UiDemo.ino
Normal file
194
examples/SSD1306UiDemo/SSD1306UiDemo.ino
Normal file
@ -0,0 +1,194 @@
|
||||
/**
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018 by ThingPulse, Daniel Eichhorn
|
||||
* Copyright (c) 2018 by Fabrice Weinberg
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* ThingPulse invests considerable time and money to develop these open source libraries.
|
||||
* Please support us by buying our products (and not the clones) from
|
||||
* https://thingpulse.com
|
||||
*
|
||||
*/
|
||||
|
||||
// Include the correct display library
|
||||
// For a connection via I2C using Wire include
|
||||
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
|
||||
// or #include "SH1106Wire.h", legacy include: `#include "SH1106.h"`
|
||||
// For a connection via I2C using brzo_i2c (must be installed) include
|
||||
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Brzo.h"
|
||||
// #include "SH1106Brzo.h"
|
||||
// For a connection via SPI include
|
||||
// #include <SPI.h> // Only needed for Arduino 1.6.5 and earlier
|
||||
// #include "SSD1306Spi.h"
|
||||
// #include "SH1106SPi.h"
|
||||
|
||||
// Include the UI lib
|
||||
#include "OLEDDisplayUi.h"
|
||||
|
||||
// Include custom images
|
||||
|
||||
#include "images.h"
|
||||
|
||||
// Use the corresponding display class:
|
||||
|
||||
// Initialize the OLED display using SPI
|
||||
// D5 -> CLK
|
||||
// D7 -> MOSI (DOUT)
|
||||
// D0 -> RES
|
||||
// D2 -> DC
|
||||
// D8 -> CS
|
||||
// SSD1306Spi display(D0, D2, D8);
|
||||
// or
|
||||
// SH1106Spi display(D0, D2);
|
||||
|
||||
// Initialize the OLED display using brzo_i2c
|
||||
// D3 -> SDA
|
||||
// D5 -> SCL
|
||||
// SSD1306Brzo display(0x3c, D3, D5);
|
||||
// or
|
||||
// SH1106Brzo display(0x3c, D3, D5);
|
||||
|
||||
// Initialize the OLED display using Wire library
|
||||
SSD1306Wire display(0x3c, D3, D5);
|
||||
// SH1106Wire 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(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
|
||||
|
||||
display->drawXbm(x + 34, y + 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
|
||||
}
|
||||
|
||||
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);
|
||||
display->setFont(ArialMT_Plain_10);
|
||||
display->drawString(0 + x, 10 + y, "Arial 10");
|
||||
|
||||
display->setFont(ArialMT_Plain_16);
|
||||
display->drawString(0 + x, 20 + y, "Arial 16");
|
||||
|
||||
display->setFont(ArialMT_Plain_24);
|
||||
display->drawString(0 + x, 34 + y, "Arial 24");
|
||||
}
|
||||
|
||||
void drawFrame3(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
|
||||
// Text alignment demo
|
||||
display->setFont(ArialMT_Plain_10);
|
||||
|
||||
// The coordinates define the left starting point of the text
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->drawString(0 + x, 11 + y, "Left aligned (0,10)");
|
||||
|
||||
// The coordinates define the center of the text
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display->drawString(64 + x, 22 + y, "Center aligned (64,22)");
|
||||
|
||||
// The coordinates define the right end of the text
|
||||
display->setTextAlignment(TEXT_ALIGN_RIGHT);
|
||||
display->drawString(128 + x, 33 + y, "Right aligned (128,33)");
|
||||
}
|
||||
|
||||
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
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(ArialMT_Plain_10);
|
||||
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(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
|
||||
|
||||
}
|
||||
|
||||
// This array keeps function pointers to all frames
|
||||
// frames are the single views that slide in
|
||||
FrameCallback frames[] = { drawFrame1, drawFrame2, drawFrame3, drawFrame4, drawFrame5 };
|
||||
|
||||
// how many frames are there?
|
||||
int frameCount = 5;
|
||||
|
||||
// Overlays are statically drawn on top of a frame eg. a clock
|
||||
OverlayCallback overlays[] = { msOverlay };
|
||||
int overlaysCount = 1;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
Serial.println();
|
||||
|
||||
// The ESP is capable of rendering 60fps in 80Mhz mode
|
||||
// but that won't give you much time for anything else
|
||||
// run it in 160Mhz mode or just set it to 30 fps
|
||||
ui.setTargetFPS(60);
|
||||
|
||||
// Customize the active and inactive symbol
|
||||
ui.setActiveSymbol(activeSymbol);
|
||||
ui.setInactiveSymbol(inactiveSymbol);
|
||||
|
||||
// You can change this to
|
||||
// TOP, LEFT, BOTTOM, RIGHT
|
||||
ui.setIndicatorPosition(BOTTOM);
|
||||
|
||||
// Defines where the first frame is located in the bar.
|
||||
ui.setIndicatorDirection(LEFT_RIGHT);
|
||||
|
||||
// You can change the transition that is used
|
||||
// SLIDE_LEFT, SLIDE_RIGHT, SLIDE_UP, SLIDE_DOWN
|
||||
ui.setFrameAnimation(SLIDE_LEFT);
|
||||
|
||||
// Add frames
|
||||
ui.setFrames(frames, frameCount);
|
||||
|
||||
// Add overlays
|
||||
ui.setOverlays(overlays, overlaysCount);
|
||||
|
||||
// Initialising the UI will init the display too.
|
||||
ui.init();
|
||||
|
||||
display.flipScreenVertically();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
int remainingTimeBudget = ui.update();
|
||||
|
||||
if (remainingTimeBudget > 0) {
|
||||
// You can do some work here
|
||||
// Don't do stuff if you are below your
|
||||
// time budget.
|
||||
delay(remainingTimeBudget);
|
||||
}
|
||||
}
|
50
examples/SSD1306UiDemo/images.h
Normal file
50
examples/SSD1306UiDemo/images.h
Normal file
@ -0,0 +1,50 @@
|
||||
#define WiFi_Logo_width 60
|
||||
#define WiFi_Logo_height 36
|
||||
const uint8_t WiFi_Logo_bits[] PROGMEM = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
|
||||
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
|
||||
0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
|
||||
0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF,
|
||||
0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00,
|
||||
0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C,
|
||||
0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00,
|
||||
0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C,
|
||||
0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00,
|
||||
0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C,
|
||||
0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00,
|
||||
0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C,
|
||||
0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00,
|
||||
0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F,
|
||||
0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00,
|
||||
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF,
|
||||
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00,
|
||||
0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
|
||||
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
const uint8_t activeSymbol[] PROGMEM = {
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00011000,
|
||||
B00100100,
|
||||
B01000010,
|
||||
B01000010,
|
||||
B00100100,
|
||||
B00011000
|
||||
};
|
||||
|
||||
const uint8_t inactiveSymbol[] PROGMEM = {
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00000000,
|
||||
B00011000,
|
||||
B00011000,
|
||||
B00000000,
|
||||
B00000000
|
||||
};
|
Reference in New Issue
Block a user