First init.
This commit is contained in:
@@ -0,0 +1,357 @@
|
||||
/*********************************************************************
|
||||
This is an example for our Monochrome OLEDs based on SH110X drivers
|
||||
|
||||
This example is for a 128x64 size display using SPi to communicate
|
||||
5 pins are required to interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above, and the splash screen must be included in any redistribution
|
||||
|
||||
SPi SH1106 modified by Rupert Hirst 12/09/21
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SH110X.h>
|
||||
|
||||
|
||||
#define OLED_MOSI 10
|
||||
#define OLED_CLK 8
|
||||
#define OLED_DC 7
|
||||
#define OLED_CS 5
|
||||
#define OLED_RST 9
|
||||
|
||||
|
||||
// Create the OLED display
|
||||
Adafruit_SH1106G display = Adafruit_SH1106G(128, 64,OLED_MOSI, OLED_CLK, OLED_DC, OLED_RST, OLED_CS);
|
||||
|
||||
|
||||
#define NUMFLAKES 10
|
||||
#define XPOS 0
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
|
||||
#define LOGO16_GLCD_HEIGHT 16
|
||||
#define LOGO16_GLCD_WIDTH 16
|
||||
static const unsigned char PROGMEM logo16_glcd_bmp[] =
|
||||
{ B00000000, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000011, B11100000,
|
||||
B11110011, B11100000,
|
||||
B11111110, B11111000,
|
||||
B01111110, B11111111,
|
||||
B00110011, B10011111,
|
||||
B00011111, B11111100,
|
||||
B00001101, B01110000,
|
||||
B00011011, B10100000,
|
||||
B00111111, B11100000,
|
||||
B00111111, B11110000,
|
||||
B01111100, B11110000,
|
||||
B01110000, B01110000,
|
||||
B00000000, B00110000
|
||||
};
|
||||
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
|
||||
//display.setContrast (0); // dim display
|
||||
|
||||
// Start OLED
|
||||
display.begin(0, true); // we dont use the i2c address but we will reset!
|
||||
|
||||
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// Clear the buffer.
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a single pixel
|
||||
display.drawPixel(10, 10, SH110X_WHITE);
|
||||
// Show the display buffer on the hardware.
|
||||
// NOTE: You _must_ call display after making any drawing commands
|
||||
// to make them visible on the display hardware!
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw many lines
|
||||
testdrawline();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw rectangles
|
||||
testdrawrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw multiple rectangles
|
||||
testfillrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw mulitple circles
|
||||
testdrawcircle();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a SH110X_WHITE circle, 10 pixel radius
|
||||
display.fillCircle(display.width() / 2, display.height() / 2, 10, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfillroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawtriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfilltriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw the first ~12 characters in the font
|
||||
testdrawchar();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
|
||||
// text display tests
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(SH110X_WHITE);
|
||||
display.setCursor(0, 0);
|
||||
display.println("Failure is always an option");
|
||||
display.setTextColor(SH110X_BLACK, SH110X_WHITE); // 'inverted' text
|
||||
display.println(3.141592);
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(SH110X_WHITE);
|
||||
display.print("0x"); display.println(0xDEADBEEF, HEX);
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// miniature bitmap display
|
||||
display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
|
||||
display.display();
|
||||
delay(1);
|
||||
|
||||
// invert the display
|
||||
display.invertDisplay(true);
|
||||
delay(1000);
|
||||
display.invertDisplay(false);
|
||||
delay(1000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a bitmap icon and 'animate' movement
|
||||
testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
|
||||
uint8_t icons[NUMFLAKES][3];
|
||||
|
||||
// initialize
|
||||
for (uint8_t f = 0; f < NUMFLAKES; f++) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
|
||||
Serial.print("x: ");
|
||||
Serial.print(icons[f][XPOS], DEC);
|
||||
Serial.print(" y: ");
|
||||
Serial.print(icons[f][YPOS], DEC);
|
||||
Serial.print(" dy: ");
|
||||
Serial.println(icons[f][DELTAY], DEC);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
// draw each icon
|
||||
for (uint8_t f = 0; f < NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SH110X_WHITE);
|
||||
}
|
||||
display.display();
|
||||
delay(200);
|
||||
|
||||
// then erase it + move it
|
||||
for (uint8_t f = 0; f < NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SH110X_BLACK);
|
||||
// move it
|
||||
icons[f][YPOS] += icons[f][DELTAY];
|
||||
// if its gone, reinit
|
||||
if (icons[f][YPOS] > display.height()) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testdrawchar(void) {
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(SH110X_WHITE);
|
||||
display.setCursor(0, 0);
|
||||
|
||||
for (uint8_t i = 0; i < 168; i++) {
|
||||
if (i == '\n') continue;
|
||||
display.write(i);
|
||||
if ((i > 0) && (i % 21 == 0))
|
||||
display.println();
|
||||
}
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
|
||||
void testdrawcircle(void) {
|
||||
for (int16_t i = 0; i < display.height(); i += 2) {
|
||||
display.drawCircle(display.width() / 2, display.height() / 2, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testfillrect(void) {
|
||||
uint8_t color = 1;
|
||||
for (int16_t i = 0; i < display.height() / 2; i += 3) {
|
||||
// alternate colors
|
||||
display.fillRect(i, i, display.width() - i * 2, display.height() - i * 2, color % 2);
|
||||
display.display();
|
||||
delay(1);
|
||||
color++;
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawtriangle(void) {
|
||||
for (int16_t i = 0; i < min(display.width(), display.height()) / 2; i += 5) {
|
||||
display.drawTriangle(display.width() / 2, display.height() / 2 - i,
|
||||
display.width() / 2 - i, display.height() / 2 + i,
|
||||
display.width() / 2 + i, display.height() / 2 + i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testfilltriangle(void) {
|
||||
uint8_t color = SH110X_WHITE;
|
||||
for (int16_t i = min(display.width(), display.height()) / 2; i > 0; i -= 5) {
|
||||
display.fillTriangle(display.width() / 2, display.height() / 2 - i,
|
||||
display.width() / 2 - i, display.height() / 2 + i,
|
||||
display.width() / 2 + i, display.height() / 2 + i, SH110X_WHITE);
|
||||
if (color == SH110X_WHITE) color = SH110X_BLACK;
|
||||
else color = SH110X_WHITE;
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawroundrect(void) {
|
||||
for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
|
||||
display.drawRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testfillroundrect(void) {
|
||||
uint8_t color = SH110X_WHITE;
|
||||
for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
|
||||
display.fillRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, color);
|
||||
if (color == SH110X_WHITE) color = SH110X_BLACK;
|
||||
else color = SH110X_WHITE;
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawrect(void) {
|
||||
for (int16_t i = 0; i < display.height() / 2; i += 2) {
|
||||
display.drawRect(i, i, display.width() - 2 * i, display.height() - 2 * i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawline() {
|
||||
for (int16_t i = 0; i < display.width(); i += 4) {
|
||||
display.drawLine(0, 0, i, display.height() - 1, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for (int16_t i = 0; i < display.height(); i += 4) {
|
||||
display.drawLine(0, 0, display.width() - 1, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i = 0; i < display.width(); i += 4) {
|
||||
display.drawLine(0, display.height() - 1, i, 0, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for (int16_t i = display.height() - 1; i >= 0; i -= 4) {
|
||||
display.drawLine(0, display.height() - 1, display.width() - 1, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i = display.width() - 1; i >= 0; i -= 4) {
|
||||
display.drawLine(display.width() - 1, display.height() - 1, i, 0, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for (int16_t i = display.height() - 1; i >= 0; i -= 4) {
|
||||
display.drawLine(display.width() - 1, display.height() - 1, 0, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i = 0; i < display.height(); i += 4) {
|
||||
display.drawLine(display.width() - 1, 0, 0, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for (int16_t i = 0; i < display.width(); i += 4) {
|
||||
display.drawLine(display.width() - 1, 0, i, display.height() - 1, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
/*********************************************************************
|
||||
This is an example for our Monochrome OLEDs based on SH110X drivers
|
||||
|
||||
This example is for a 128x64 size display using I2C to communicate
|
||||
3 pins are required to interface (2 I2C and one reset)
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above, and the splash screen must be included in any redistribution
|
||||
|
||||
i2c SH1106 modified by Rupert Hirst 12/09/21
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SH110X.h>
|
||||
|
||||
/* Uncomment the initialize the I2C address , uncomment only one, If you get a totally blank screen try the other*/
|
||||
#define i2c_Address 0x3c //initialize with the I2C addr 0x3C Typically eBay OLED's
|
||||
//#define i2c_Address 0x3d //initialize with the I2C addr 0x3D Typically Adafruit OLED's
|
||||
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
|
||||
#define OLED_RESET -1 // QT-PY / XIAO
|
||||
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
|
||||
|
||||
#define NUMFLAKES 10
|
||||
#define XPOS 0
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
|
||||
#define LOGO16_GLCD_HEIGHT 16
|
||||
#define LOGO16_GLCD_WIDTH 16
|
||||
static const unsigned char PROGMEM logo16_glcd_bmp[] =
|
||||
{ B00000000, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000001, B11000000,
|
||||
B00000011, B11100000,
|
||||
B11110011, B11100000,
|
||||
B11111110, B11111000,
|
||||
B01111110, B11111111,
|
||||
B00110011, B10011111,
|
||||
B00011111, B11111100,
|
||||
B00001101, B01110000,
|
||||
B00011011, B10100000,
|
||||
B00111111, B11100000,
|
||||
B00111111, B11110000,
|
||||
B01111100, B11110000,
|
||||
B01110000, B01110000,
|
||||
B00000000, B00110000
|
||||
};
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
|
||||
delay(250); // wait for the OLED to power up
|
||||
display.begin(i2c_Address, true); // Address 0x3C default
|
||||
//display.setContrast (0); // dim display
|
||||
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// Clear the buffer.
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a single pixel
|
||||
display.drawPixel(10, 10, SH110X_WHITE);
|
||||
// Show the display buffer on the hardware.
|
||||
// NOTE: You _must_ call display after making any drawing commands
|
||||
// to make them visible on the display hardware!
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw many lines
|
||||
testdrawline();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw rectangles
|
||||
testdrawrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw multiple rectangles
|
||||
testfillrect();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw mulitple circles
|
||||
testdrawcircle();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a SH110X_WHITE circle, 10 pixel radius
|
||||
display.fillCircle(display.width() / 2, display.height() / 2, 10, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfillroundrect();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawtriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testfilltriangle();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw the first ~12 characters in the font
|
||||
testdrawchar();
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
|
||||
|
||||
// text display tests
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(SH110X_WHITE);
|
||||
display.setCursor(0, 0);
|
||||
display.println("Failure is always an option");
|
||||
display.setTextColor(SH110X_BLACK, SH110X_WHITE); // 'inverted' text
|
||||
display.println(3.141592);
|
||||
display.setTextSize(2);
|
||||
display.setTextColor(SH110X_WHITE);
|
||||
display.print("0x"); display.println(0xDEADBEEF, HEX);
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
// miniature bitmap display
|
||||
display.drawBitmap(30, 16, logo16_glcd_bmp, 16, 16, 1);
|
||||
display.display();
|
||||
delay(1);
|
||||
|
||||
// invert the display
|
||||
display.invertDisplay(true);
|
||||
delay(1000);
|
||||
display.invertDisplay(false);
|
||||
delay(1000);
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a bitmap icon and 'animate' movement
|
||||
testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
|
||||
uint8_t icons[NUMFLAKES][3];
|
||||
|
||||
// initialize
|
||||
for (uint8_t f = 0; f < NUMFLAKES; f++) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
|
||||
Serial.print("x: ");
|
||||
Serial.print(icons[f][XPOS], DEC);
|
||||
Serial.print(" y: ");
|
||||
Serial.print(icons[f][YPOS], DEC);
|
||||
Serial.print(" dy: ");
|
||||
Serial.println(icons[f][DELTAY], DEC);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
// draw each icon
|
||||
for (uint8_t f = 0; f < NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SH110X_WHITE);
|
||||
}
|
||||
display.display();
|
||||
delay(200);
|
||||
|
||||
// then erase it + move it
|
||||
for (uint8_t f = 0; f < NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SH110X_BLACK);
|
||||
// move it
|
||||
icons[f][YPOS] += icons[f][DELTAY];
|
||||
// if its gone, reinit
|
||||
if (icons[f][YPOS] > display.height()) {
|
||||
icons[f][XPOS] = random(display.width());
|
||||
icons[f][YPOS] = 0;
|
||||
icons[f][DELTAY] = random(5) + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void testdrawchar(void) {
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(SH110X_WHITE);
|
||||
display.setCursor(0, 0);
|
||||
|
||||
for (uint8_t i = 0; i < 168; i++) {
|
||||
if (i == '\n') continue;
|
||||
display.write(i);
|
||||
if ((i > 0) && (i % 21 == 0))
|
||||
display.println();
|
||||
}
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
|
||||
void testdrawcircle(void) {
|
||||
for (int16_t i = 0; i < display.height(); i += 2) {
|
||||
display.drawCircle(display.width() / 2, display.height() / 2, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testfillrect(void) {
|
||||
uint8_t color = 1;
|
||||
for (int16_t i = 0; i < display.height() / 2; i += 3) {
|
||||
// alternate colors
|
||||
display.fillRect(i, i, display.width() - i * 2, display.height() - i * 2, color % 2);
|
||||
display.display();
|
||||
delay(1);
|
||||
color++;
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawtriangle(void) {
|
||||
for (int16_t i = 0; i < min(display.width(), display.height()) / 2; i += 5) {
|
||||
display.drawTriangle(display.width() / 2, display.height() / 2 - i,
|
||||
display.width() / 2 - i, display.height() / 2 + i,
|
||||
display.width() / 2 + i, display.height() / 2 + i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testfilltriangle(void) {
|
||||
uint8_t color = SH110X_WHITE;
|
||||
for (int16_t i = min(display.width(), display.height()) / 2; i > 0; i -= 5) {
|
||||
display.fillTriangle(display.width() / 2, display.height() / 2 - i,
|
||||
display.width() / 2 - i, display.height() / 2 + i,
|
||||
display.width() / 2 + i, display.height() / 2 + i, SH110X_WHITE);
|
||||
if (color == SH110X_WHITE) color = SH110X_BLACK;
|
||||
else color = SH110X_WHITE;
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawroundrect(void) {
|
||||
for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
|
||||
display.drawRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testfillroundrect(void) {
|
||||
uint8_t color = SH110X_WHITE;
|
||||
for (int16_t i = 0; i < display.height() / 2 - 2; i += 2) {
|
||||
display.fillRoundRect(i, i, display.width() - 2 * i, display.height() - 2 * i, display.height() / 4, color);
|
||||
if (color == SH110X_WHITE) color = SH110X_BLACK;
|
||||
else color = SH110X_WHITE;
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawrect(void) {
|
||||
for (int16_t i = 0; i < display.height() / 2; i += 2) {
|
||||
display.drawRect(i, i, display.width() - 2 * i, display.height() - 2 * i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
void testdrawline() {
|
||||
for (int16_t i = 0; i < display.width(); i += 4) {
|
||||
display.drawLine(0, 0, i, display.height() - 1, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for (int16_t i = 0; i < display.height(); i += 4) {
|
||||
display.drawLine(0, 0, display.width() - 1, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i = 0; i < display.width(); i += 4) {
|
||||
display.drawLine(0, display.height() - 1, i, 0, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for (int16_t i = display.height() - 1; i >= 0; i -= 4) {
|
||||
display.drawLine(0, display.height() - 1, display.width() - 1, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i = display.width() - 1; i >= 0; i -= 4) {
|
||||
display.drawLine(display.width() - 1, display.height() - 1, i, 0, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for (int16_t i = display.height() - 1; i >= 0; i -= 4) {
|
||||
display.drawLine(display.width() - 1, display.height() - 1, 0, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
for (int16_t i = 0; i < display.height(); i += 4) {
|
||||
display.drawLine(display.width() - 1, 0, 0, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for (int16_t i = 0; i < display.width(); i += 4) {
|
||||
display.drawLine(display.width() - 1, 0, i, display.height() - 1, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SH110X.h>
|
||||
|
||||
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
|
||||
|
||||
// OLED FeatherWing buttons map to different pins depending on board:
|
||||
#if defined(ESP8266)
|
||||
#define BUTTON_A 0
|
||||
#define BUTTON_B 16
|
||||
#define BUTTON_C 2
|
||||
#elif defined(ESP32) && !defined(ARDUINO_ADAFRUIT_FEATHER_ESP32S2)
|
||||
#define BUTTON_A 15
|
||||
#define BUTTON_B 32
|
||||
#define BUTTON_C 14
|
||||
#elif defined(ARDUINO_STM32_FEATHER)
|
||||
#define BUTTON_A PA15
|
||||
#define BUTTON_B PC7
|
||||
#define BUTTON_C PC5
|
||||
#elif defined(TEENSYDUINO)
|
||||
#define BUTTON_A 4
|
||||
#define BUTTON_B 3
|
||||
#define BUTTON_C 8
|
||||
#elif defined(ARDUINO_NRF52832_FEATHER)
|
||||
#define BUTTON_A 31
|
||||
#define BUTTON_B 30
|
||||
#define BUTTON_C 27
|
||||
#else // 32u4, M0, M4, nrf52840, esp32-s2 and 328p
|
||||
#define BUTTON_A 9
|
||||
#define BUTTON_B 6
|
||||
#define BUTTON_C 5
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("128x64 OLED FeatherWing test");
|
||||
delay(250); // wait for the OLED to power up
|
||||
display.begin(0x3C, true); // Address 0x3C default
|
||||
|
||||
Serial.println("OLED begun");
|
||||
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
display.display();
|
||||
delay(1000);
|
||||
|
||||
// Clear the buffer.
|
||||
display.clearDisplay();
|
||||
display.display();
|
||||
|
||||
display.setRotation(1);
|
||||
Serial.println("Button test");
|
||||
|
||||
pinMode(BUTTON_A, INPUT_PULLUP);
|
||||
pinMode(BUTTON_B, INPUT_PULLUP);
|
||||
pinMode(BUTTON_C, INPUT_PULLUP);
|
||||
|
||||
// text display tests
|
||||
display.setTextSize(1);
|
||||
display.setTextColor(SH110X_WHITE);
|
||||
display.setCursor(0,0);
|
||||
display.print("Connecting to SSID\n'adafruit':");
|
||||
display.print("connected!");
|
||||
display.println("IP: 10.0.1.23");
|
||||
display.println("Sending val #0");
|
||||
display.display(); // actually display all of the above
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if(!digitalRead(BUTTON_A)) display.print("A");
|
||||
if(!digitalRead(BUTTON_B)) display.print("B");
|
||||
if(!digitalRead(BUTTON_C)) display.print("C");
|
||||
delay(10);
|
||||
yield();
|
||||
display.display();
|
||||
}
|
||||
@@ -0,0 +1,374 @@
|
||||
/*********************************************************************
|
||||
This is an example for our Monochrome OLEDs based on SH1107 drivers
|
||||
|
||||
This example is for a 128x128 size display using I2C to communicate
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above, and the splash screen must be included in any redistribution
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SH110X.h>
|
||||
|
||||
#define SCREEN_WIDTH 128 // OLED display width, in pixels
|
||||
#define SCREEN_HEIGHT 128 // OLED display height, in pixels
|
||||
#define OLED_RESET -1 // can set an oled reset pin if desired
|
||||
Adafruit_SH1107 display = Adafruit_SH1107(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET, 1000000, 100000);
|
||||
|
||||
|
||||
#define NUMFLAKES 10
|
||||
#define XPOS 0
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
|
||||
#define LOGO_HEIGHT 16
|
||||
#define LOGO_WIDTH 16
|
||||
static const unsigned char PROGMEM logo_bmp[] =
|
||||
{ 0b00000000, 0b11000000,
|
||||
0b00000001, 0b11000000,
|
||||
0b00000001, 0b11000000,
|
||||
0b00000011, 0b11100000,
|
||||
0b11110011, 0b11100000,
|
||||
0b11111110, 0b11111000,
|
||||
0b01111110, 0b11111111,
|
||||
0b00110011, 0b10011111,
|
||||
0b00011111, 0b11111100,
|
||||
0b00001101, 0b01110000,
|
||||
0b00011011, 0b10100000,
|
||||
0b00111111, 0b11100000,
|
||||
0b00111111, 0b11110000,
|
||||
0b01111100, 0b11110000,
|
||||
0b01110000, 0b01110000,
|
||||
0b00000000, 0b00110000 };
|
||||
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
delay(250); // wait for the OLED to power up
|
||||
|
||||
// Show image buffer on the display hardware.
|
||||
// Since the buffer is intialized with an Adafruit splashscreen
|
||||
// internally, this will display the splashscreen.
|
||||
|
||||
display.begin(0x3D, true); // Address 0x3D default
|
||||
//display.setContrast (0); // dim display
|
||||
|
||||
display.display();
|
||||
delay(2000);
|
||||
|
||||
// Clear the buffer.
|
||||
display.clearDisplay();
|
||||
|
||||
// draw a single pixel
|
||||
display.drawPixel(10, 10, SH110X_WHITE);
|
||||
// Show the display buffer on the hardware.
|
||||
// NOTE: You _must_ call display after making any drawing commands
|
||||
// to make them visible on the display hardware!
|
||||
display.display();
|
||||
delay(2000);
|
||||
display.clearDisplay();
|
||||
|
||||
testdrawline(); // Draw many lines
|
||||
|
||||
testdrawrect(); // Draw rectangles (outlines)
|
||||
|
||||
testfillrect(); // Draw rectangles (filled)
|
||||
|
||||
testdrawcircle(); // Draw circles (outlines)
|
||||
|
||||
testfillcircle(); // Draw circles (filled)
|
||||
|
||||
testdrawroundrect(); // Draw rounded rectangles (outlines)
|
||||
|
||||
testfillroundrect(); // Draw rounded rectangles (filled)
|
||||
|
||||
testdrawtriangle(); // Draw triangles (outlines)
|
||||
|
||||
testfilltriangle(); // Draw triangles (filled)
|
||||
|
||||
testdrawchar(); // Draw characters of the default font
|
||||
|
||||
testdrawstyles(); // Draw 'stylized' characters
|
||||
|
||||
testdrawbitmap(); // Draw a small bitmap image
|
||||
|
||||
testanimate(logo_bmp, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps
|
||||
}
|
||||
|
||||
void loop() {
|
||||
}
|
||||
|
||||
void testdrawline() {
|
||||
int16_t i;
|
||||
|
||||
display.clearDisplay(); // Clear display buffer
|
||||
|
||||
for(i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, 0, i, display.height()-1, SH110X_WHITE);
|
||||
display.display(); // Update screen with each newly-drawn line
|
||||
delay(1);
|
||||
}
|
||||
for(i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(0, 0, display.width()-1, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
|
||||
for(i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(0, display.height()-1, i, 0, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for(i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(0, display.height()-1, display.width()-1, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
|
||||
for(i=display.width()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, i, 0, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for(i=display.height()-1; i>=0; i-=4) {
|
||||
display.drawLine(display.width()-1, display.height()-1, 0, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
delay(250);
|
||||
|
||||
display.clearDisplay();
|
||||
|
||||
for(i=0; i<display.height(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, 0, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
for(i=0; i<display.width(); i+=4) {
|
||||
display.drawLine(display.width()-1, 0, i, display.height()-1, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
|
||||
delay(2000); // Pause for 2 seconds
|
||||
}
|
||||
|
||||
void testdrawrect(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
for(int16_t i=0; i<display.height()/2; i+=2) {
|
||||
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, SH110X_WHITE);
|
||||
display.display(); // Update screen with each newly-drawn rectangle
|
||||
delay(1);
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testfillrect(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
for(int16_t i=0; i<display.height()/2; i+=3) {
|
||||
// The INVERSE color is used so rectangles alternate white/black
|
||||
display.fillRect(i, i, display.width()-i*2, display.height()-i*2, SH110X_INVERSE);
|
||||
display.display(); // Update screen with each newly-drawn rectangle
|
||||
delay(1);
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testdrawcircle(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
for(int16_t i=0; i<max(display.width(),display.height())/2; i+=2) {
|
||||
display.drawCircle(display.width()/2, display.height()/2, i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testfillcircle(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
for(int16_t i=max(display.width(),display.height())/2; i>0; i-=3) {
|
||||
// The INVERSE color is used so circles alternate white/black
|
||||
display.fillCircle(display.width() / 2, display.height() / 2, i, SH110X_INVERSE);
|
||||
display.display(); // Update screen with each newly-drawn circle
|
||||
delay(1);
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testdrawroundrect(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
for(int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i,
|
||||
display.height()/4, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testfillroundrect(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
for(int16_t i=0; i<display.height()/2-2; i+=2) {
|
||||
// The INVERSE color is used so round-rects alternate white/black
|
||||
display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i,
|
||||
display.height()/4, SH110X_INVERSE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testdrawtriangle(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
for(int16_t i=0; i<max(display.width(),display.height())/2; i+=5) {
|
||||
display.drawTriangle(
|
||||
display.width()/2 , display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, SH110X_WHITE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testfilltriangle(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
for(int16_t i=max(display.width(),display.height())/2; i>0; i-=5) {
|
||||
// The INVERSE color is used so triangles alternate white/black
|
||||
display.fillTriangle(
|
||||
display.width()/2 , display.height()/2-i,
|
||||
display.width()/2-i, display.height()/2+i,
|
||||
display.width()/2+i, display.height()/2+i, SH110X_INVERSE);
|
||||
display.display();
|
||||
delay(1);
|
||||
}
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testdrawchar(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
display.setTextSize(1); // Normal 1:1 pixel scale
|
||||
display.setTextColor(SH110X_WHITE); // Draw white text
|
||||
display.setCursor(0, 0); // Start at top-left corner
|
||||
display.cp437(true); // Use full 256 char 'Code Page 437' font
|
||||
|
||||
// Not all the characters will fit on the display. This is normal.
|
||||
// Library will draw what it can and the rest will be clipped.
|
||||
for(int16_t i=0; i<256; i++) {
|
||||
if(i == '\n') display.write(' ');
|
||||
else display.write(i);
|
||||
}
|
||||
|
||||
display.display();
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testdrawstyles(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
display.setTextSize(1); // Normal 1:1 pixel scale
|
||||
display.setTextColor(SH110X_WHITE); // Draw white text
|
||||
display.setCursor(0,0); // Start at top-left corner
|
||||
display.println(F("Hello, world!"));
|
||||
|
||||
display.setTextColor(SH110X_BLACK, SH110X_WHITE); // Draw 'inverse' text
|
||||
display.println(3.141592);
|
||||
|
||||
display.setTextSize(2); // Draw 2X-scale text
|
||||
display.setTextColor(SH110X_WHITE);
|
||||
display.print(F("0x")); display.println(0xDEADBEEF, HEX);
|
||||
|
||||
display.display();
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
void testdrawbitmap(void) {
|
||||
display.clearDisplay();
|
||||
|
||||
display.drawBitmap(
|
||||
(display.width() - LOGO_WIDTH ) / 2,
|
||||
(display.height() - LOGO_HEIGHT) / 2,
|
||||
logo_bmp, LOGO_WIDTH, LOGO_HEIGHT, 1);
|
||||
display.display();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
#define XPOS 0 // Indexes into the 'icons' array in function below
|
||||
#define YPOS 1
|
||||
#define DELTAY 2
|
||||
|
||||
void testanimate(const uint8_t *bitmap, uint8_t w, uint8_t h) {
|
||||
int8_t f, icons[NUMFLAKES][3];
|
||||
|
||||
// Initialize 'snowflake' positions
|
||||
for(f=0; f< NUMFLAKES; f++) {
|
||||
icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width());
|
||||
icons[f][YPOS] = -LOGO_HEIGHT;
|
||||
icons[f][DELTAY] = random(1, 6);
|
||||
Serial.print(F("x: "));
|
||||
Serial.print(icons[f][XPOS], DEC);
|
||||
Serial.print(F(" y: "));
|
||||
Serial.print(icons[f][YPOS], DEC);
|
||||
Serial.print(F(" dy: "));
|
||||
Serial.println(icons[f][DELTAY], DEC);
|
||||
}
|
||||
|
||||
for(;;) { // Loop forever...
|
||||
display.clearDisplay(); // Clear the display buffer
|
||||
|
||||
// Draw each snowflake:
|
||||
for(f=0; f< NUMFLAKES; f++) {
|
||||
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, SH110X_WHITE);
|
||||
}
|
||||
|
||||
display.display(); // Show the display buffer on the screen
|
||||
delay(200); // Pause for 1/10 second
|
||||
|
||||
// Then update coordinates of each flake...
|
||||
for(f=0; f< NUMFLAKES; f++) {
|
||||
icons[f][YPOS] += icons[f][DELTAY];
|
||||
// If snowflake is off the bottom of the screen...
|
||||
if (icons[f][YPOS] >= display.height()) {
|
||||
// Reinitialize to a random position, just off the top
|
||||
icons[f][XPOS] = random(1 - LOGO_WIDTH, display.width());
|
||||
icons[f][YPOS] = -LOGO_HEIGHT;
|
||||
icons[f][DELTAY] = random(1, 6);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user