#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);
const int buttonPin = 6; // Change to your button pin
bool buttonPressed = false;
int dropPositionX[10]; // Array to store X positions of water drops
int dropPositionY[10]; // Array to store Y positions of water drops
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;) {}
}
display.clearDisplay();
}
void loop() {
buttonPressed = digitalRead(buttonPin);
if (buttonPressed) {
animateWater();
} else {
display.clearDisplay();
display.display();
}
}
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 diagonally
for (int i = 0; i < 10; i++) {
dropPositionX[i] -= 1; // Move the water drop towards left
dropPositionY[i] += 1; // Move the water drop downwards
if (dropPositionX[i] < 100 || dropPositionY[i] > 63) { // If water drop reaches the end of the pipe or the bottom of the display
dropPositionX[i] = random(113, 117); // Reset its X position to a random point between 113 and 117
dropPositionY[i] = random(0, 5); // Reset its Y position to a random point between 0 and 5
}
// 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(1); // Adjust the delay for desired animation speed
}