Skip to content

Instantly share code, notes, and snippets.

@jaylandro
Created February 21, 2022 15:35
Show Gist options
  • Save jaylandro/1ee35bd3862b9b5765977c01df9d7134 to your computer and use it in GitHub Desktop.
Save jaylandro/1ee35bd3862b9b5765977c01df9d7134 to your computer and use it in GitHub Desktop.
Adafruit_SH1107 for Arduino IDE and Qt PY
/*********************************************************************
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);
#define NUMFLAKES 4
#define XPOS 0
#define YPOS 1
#define DELTAY 2
#define LOGO_HEIGHT 90
#define LOGO_WIDTH 85
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 };
// '2hexagonhexagram', 84x90px
const unsigned char epd_bitmap_2hexagonhexagram [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f,
0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf1, 0xfc, 0xf0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x86, 0xb2, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06,
0x18, 0x28, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x21, 0x28, 0x61, 0x80, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x82, 0x24, 0x18, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x23, 0x02, 0x20, 0x06, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x04, 0x22, 0x01, 0x30,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x04, 0x21, 0x00, 0xd0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xc0, 0x08, 0x21, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x18, 0x21, 0x80,
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xfc, 0x10, 0x20, 0xc3, 0xff, 0xf8, 0x00, 0x00, 0x00,
0x03, 0x9f, 0x67, 0xa0, 0x20, 0x5e, 0x3f, 0x8e, 0x00, 0x00, 0x00, 0x0c, 0x25, 0x90, 0xe0, 0x20,
0x70, 0xd6, 0x61, 0x80, 0x00, 0x00, 0x30, 0xcd, 0x04, 0x70, 0x20, 0xe3, 0x17, 0x10, 0xc0, 0x00,
0x00, 0x63, 0x0d, 0x43, 0x58, 0x21, 0x94, 0x25, 0x0c, 0x30, 0x00, 0x01, 0x8c, 0x19, 0x20, 0xc4,
0x23, 0x18, 0x25, 0x83, 0x18, 0x00, 0x03, 0x10, 0x19, 0x21, 0x22, 0x24, 0x68, 0x45, 0x40, 0xcc,
0x00, 0x02, 0x60, 0x29, 0x11, 0x09, 0x28, 0x88, 0x05, 0x40, 0x26, 0x00, 0x05, 0x80, 0x29, 0x12,
0x07, 0xba, 0x04, 0x84, 0xa0, 0x1b, 0x00, 0x0e, 0x00, 0x49, 0x0a, 0x01, 0xfc, 0x03, 0x04, 0x80,
0x07, 0x00, 0x0e, 0x00, 0xd9, 0x0e, 0x01, 0xfc, 0x07, 0x85, 0xf0, 0x03, 0x80, 0x1c, 0x01, 0x99,
0x0c, 0x3f, 0xff, 0xc3, 0x05, 0x98, 0x03, 0xc0, 0x3e, 0x01, 0x09, 0x08, 0x71, 0xfc, 0xf3, 0x04,
0x88, 0x07, 0xc0, 0x35, 0x81, 0x09, 0x13, 0xc6, 0xf2, 0x1c, 0x84, 0x84, 0x19, 0xc0, 0x24, 0x62,
0x09, 0x17, 0x18, 0xb9, 0x8e, 0x85, 0x04, 0x22, 0xa0, 0x62, 0x10, 0x09, 0x2d, 0x21, 0xa8, 0x6b,
0x45, 0x02, 0x80, 0xa0, 0x40, 0x0c, 0x09, 0x38, 0xc1, 0x2c, 0x18, 0xe5, 0x03, 0x04, 0xa0, 0x41,
0x0b, 0x0d, 0x73, 0x03, 0x28, 0x14, 0x65, 0x05, 0x08, 0x90, 0x40, 0x88, 0xc5, 0x6c, 0x45, 0x2a,
0x23, 0x37, 0x10, 0x88, 0x90, 0x80, 0x90, 0x25, 0xd0, 0x25, 0x29, 0x20, 0xd6, 0x60, 0x90, 0x90,
0x80, 0x50, 0x0f, 0xe0, 0x29, 0x2d, 0x40, 0x3f, 0x80, 0x40, 0x90, 0x80, 0x60, 0x0f, 0xf0, 0x3b,
0x2d, 0xc0, 0xff, 0x00, 0x60, 0x90, 0x80, 0x60, 0xff, 0xfe, 0x19, 0x2d, 0xc7, 0xff, 0xf0, 0x60,
0x90, 0x80, 0x63, 0x8f, 0xc7, 0x89, 0x25, 0x4f, 0x3f, 0x9e, 0x40, 0x90, 0x80, 0x9c, 0x37, 0xf0,
0xe5, 0x2d, 0x78, 0xd6, 0x63, 0x90, 0x90, 0x40, 0xb8, 0x45, 0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 0xe3, 0xa9, 0x25, 0x5e, 0x7e, 0x8e, 0x50, 0x90, 0x00, 0x61, 0xff,
0xff, 0x19, 0x25, 0xc7, 0xff, 0xf8, 0x60, 0x90, 0x80, 0x20, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff,
0x80, 0x60, 0x90, 0x80, 0x60, 0x0f, 0xc0, 0x19, 0x25, 0x40, 0x3f, 0x00, 0x60, 0x90, 0x80, 0x90,
0x37, 0xe0, 0x25, 0x2d, 0x40, 0x5e, 0xc0, 0x90, 0x90, 0x40, 0x88, 0xc5, 0xc8, 0x65, 0x2a, 0x21,
0xb7, 0x30, 0x98, 0x90, 0x41, 0x09, 0x05, 0x66, 0x43, 0x2a, 0x06, 0x65, 0x09, 0x08, 0x90, 0x41,
0x0e, 0x0d, 0x71, 0x83, 0x2c, 0x18, 0xe5, 0x07, 0x04, 0xa0, 0x42, 0x1c, 0x09, 0x28, 0xc1, 0xac,
0x39, 0xc5, 0x03, 0x84, 0xa0, 0x20, 0x62, 0x09, 0x17, 0x10, 0xa8, 0xcb, 0x45, 0x00, 0x62, 0xa0,
0x24, 0x80, 0x09, 0x13, 0x8c, 0xfb, 0x0c, 0x84, 0x84, 0x12, 0xc0, 0x3e, 0x01, 0x09, 0x0a, 0xe3,
0x74, 0x7c, 0x84, 0x88, 0x05, 0xc0, 0x1c, 0x01, 0x89, 0x0e, 0x3f, 0xff, 0xe3, 0x04, 0x88, 0x03,
0xc0, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x0e, 0x00, 0x49, 0x0c,
0x01, 0xf8, 0x03, 0x04, 0x90, 0x03, 0x80, 0x05, 0x00, 0x49, 0x0a, 0x03, 0xfc, 0x04, 0x84, 0xa0,
0x0f, 0x00, 0x06, 0x40, 0x29, 0x11, 0x0d, 0xa9, 0x04, 0x84, 0xa0, 0x32, 0x00, 0x03, 0x30, 0x19,
0x11, 0x33, 0x2c, 0xc8, 0x45, 0x40, 0x44, 0x00, 0x01, 0x8c, 0x19, 0x20, 0xc6, 0x22, 0x38, 0x45,
0x81, 0x88, 0x00, 0x00, 0xc2, 0x0d, 0x41, 0x8c, 0x21, 0x18, 0x25, 0x86, 0x30, 0x00, 0x00, 0x61,
0x8d, 0x46, 0x58, 0x20, 0xe6, 0x05, 0x08, 0x60, 0x00, 0x00, 0x18, 0x65, 0x98, 0x60, 0x20, 0x71,
0x97, 0x21, 0x80, 0x00, 0x00, 0x07, 0x17, 0xa1, 0xe0, 0x20, 0x5c, 0x6e, 0xc7, 0x00, 0x00, 0x00,
0x01, 0xef, 0xde, 0x10, 0x20, 0x47, 0xff, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff,
0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc0, 0x08, 0x20, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0xe0, 0x08, 0x21, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x04,
0x22, 0x01, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x00, 0x22, 0x02, 0x20, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x31, 0x02, 0x24, 0x0c, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18,
0x41, 0x24, 0x31, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x31, 0x28, 0x43, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x0c, 0xa9, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xe2, 0x36, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x39, 0xf9, 0xe0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(9600);
display.begin(0x3D, true); // Address 0x3D default
display.setContrast (0); // dim display
testanimate(epd_bitmap_2hexagonhexagram, LOGO_WIDTH, LOGO_HEIGHT); // Animate bitmaps
}
void loop() {
}
#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);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment