#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int dropPositionX[10]; // Array to store X positions of water drops
int dropPositionY[10]; // Array to store Y positions of water drops
void setup() {
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
display.display();
}
void loop() {
animateWater();
}
void animateWater() {
// Erase the previous water drops
for (int i = 0; i < 10; i++) {
display.fillRect(dropPositionX[i], dropPositionY[i], 3, 3, BLACK);
}
// Move water drops horizontally
for (int i = 0; i < 10; i++) {
dropPositionX[i] -= 1; // Move the water drop towards left
if (dropPositionX[i] < 100) { // If water drop reaches the end of the pipe
dropPositionX[i] = random(100, 127); // Reset its position to a random point on the pipe
dropPositionY[i] = 8; // Set the Y position to just below the pipe
}
else {
dropPositionY[i] += random(-1, 2); // Add randomness to the Y position to simulate splashing
}
// Draw the water drops at the new positions
display.fillCircle(dropPositionX[i], dropPositionY[i], 1, WHITE); // Draw water droplets
}
// Display the changes
display.display();
// Introduce a short delay to control animation speed
delay(100); // Adjust the delay for desired animation speed
}