Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <WiFi.h>
- #include <ESPmDNS.h>
- #include <WiFiUdp.h>
- #include <ArduinoOTA.h>
- const char* ssid = "*******";
- const char* password = "*******";
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #define SCREEN_WIDTH 128 // OLED display width, in pixels
- #define SCREEN_HEIGHT 32 // OLED display height, in pixels
- #define OLED_RESET 4 // Reset pin # (or -1 if sharing Arduino reset pin)
- #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- #define NUMFLAKES 7 // Number of snowflakes in the animation example
- #define XPOS 0 // Indexes into the 'icons' array
- #define YPOS 1
- #define DELTAY 2
- #define IMG 3
- int8_t f, icons[NUMFLAKES][4];
- #define LOGO_HEIGHT 32
- #define LOGO_WIDTH 32
- #include "images.h"
- #define NUM_IMGS 3
- static const unsigned char* imgs[NUM_IMGS] = {cid_x, cid_s, skull};
- bool invert = false;
- void setup() {
- if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
- for(;;); // Don't proceed, loop forever
- }
- display.clearDisplay();
- testdrawbitmap(cid_xs, 64, 32);
- WiFi.mode(WIFI_STA);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- }
- ArduinoOTA.setHostname("ESP32 OLED");
- ArduinoOTA.setPort(3232);
- ArduinoOTA.begin();
- // 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);
- icons[f][IMG] = random(0, NUM_IMGS);
- }
- }
- void loop() {
- ArduinoOTA.handle();
- display.clearDisplay(); // Clear the display buffer
- // Draw each snowflake:
- for(f=0; f< NUMFLAKES; f++) {
- display.drawBitmap(icons[f][XPOS], icons[f][YPOS], imgs[icons[f][IMG]], LOGO_WIDTH, LOGO_HEIGHT, SSD1306_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);
- icons[f][IMG] = random(0, NUM_IMGS);
- }
- }
- }
- void testdrawbitmap(const uint8_t *bmp, uint8_t w, uint8_t h) {
- display.clearDisplay();
- display.drawBitmap(
- (display.width() - w ) / 2,
- (display.height() - h) / 2,
- bmp, w, h, 1);
- display.display();
- delay(3000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement