HaLo2FrEeEk

sketch.ino

Oct 23rd, 2021
1,003
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <WiFi.h>
  2. #include <ESPmDNS.h>
  3. #include <WiFiUdp.h>
  4. #include <ArduinoOTA.h>
  5.  
  6. const char* ssid = "*******";
  7. const char* password = "*******";
  8.  
  9. #include <Adafruit_GFX.h>
  10. #include <Adafruit_SSD1306.h>
  11.  
  12. #define SCREEN_WIDTH 128 // OLED display width, in pixels
  13. #define SCREEN_HEIGHT 32 // OLED display height, in pixels
  14.  
  15. #define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
  16. #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
  17. Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
  18.  
  19. #define NUMFLAKES     7 // Number of snowflakes in the animation example
  20.  
  21. #define XPOS   0 // Indexes into the 'icons' array
  22. #define YPOS   1
  23. #define DELTAY 2
  24. #define IMG    3
  25.  
  26. int8_t f, icons[NUMFLAKES][4];
  27.  
  28. #define LOGO_HEIGHT 32
  29. #define LOGO_WIDTH  32
  30.  
  31. #include "images.h"
  32. #define NUM_IMGS      3
  33. static const unsigned char* imgs[NUM_IMGS] = {cid_x, cid_s, skull};
  34.  
  35. bool invert = false;
  36.  
  37. void setup() {
  38.   if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
  39.     for(;;); // Don't proceed, loop forever
  40.   }
  41.   display.clearDisplay();
  42.  
  43.   testdrawbitmap(cid_xs, 64, 32);
  44.  
  45.   WiFi.mode(WIFI_STA);
  46.   WiFi.begin(ssid, password);
  47.  
  48.   while (WiFi.status() != WL_CONNECTED) {
  49.     delay(500);
  50.   }
  51.  
  52.   ArduinoOTA.setHostname("ESP32 OLED");
  53.   ArduinoOTA.setPort(3232);
  54.   ArduinoOTA.begin();
  55.  
  56.   // Initialize 'snowflake' positions
  57.   for(f=0; f< NUMFLAKES; f++) {
  58.     icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
  59.     icons[f][YPOS]   = -LOGO_HEIGHT;
  60.     icons[f][DELTAY] = random(1, 6);
  61.     icons[f][IMG]    = random(0, NUM_IMGS);
  62.   }
  63. }
  64.  
  65. void loop() {
  66.   ArduinoOTA.handle();
  67.  
  68.   display.clearDisplay(); // Clear the display buffer
  69.  
  70.   // Draw each snowflake:
  71.   for(f=0; f< NUMFLAKES; f++) {
  72.     display.drawBitmap(icons[f][XPOS], icons[f][YPOS], imgs[icons[f][IMG]], LOGO_WIDTH, LOGO_HEIGHT, SSD1306_WHITE);
  73.   }
  74.  
  75.   display.display(); // Show the display buffer on the screen
  76.   delay(200);        // Pause for 1/10 second
  77.  
  78.   // Then update coordinates of each flake...
  79.   for(f=0; f< NUMFLAKES; f++) {
  80.     icons[f][YPOS] += icons[f][DELTAY];
  81.      // If snowflake is off the bottom of the screen...
  82.     if (icons[f][YPOS] >= display.height()) {
  83.       // Reinitialize to a random position, just off the top
  84.       icons[f][XPOS]   = random(1 - LOGO_WIDTH, display.width());
  85.       icons[f][YPOS]   = -LOGO_HEIGHT;
  86.       icons[f][DELTAY] = random(1, 6);
  87.       icons[f][IMG]    = random(0, NUM_IMGS);
  88.     }
  89.   }
  90. }
  91.  
  92. void testdrawbitmap(const uint8_t *bmp, uint8_t w, uint8_t h) {
  93.   display.clearDisplay();
  94.  
  95.   display.drawBitmap(
  96.     (display.width()  - w ) / 2,
  97.     (display.height() - h) / 2,
  98.     bmp, w, h, 1);
  99.   display.display();
  100.   delay(3000);
  101. }
RAW Paste Data