#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 waterPosition = 0; // Initialize water position at the top of the pipe
void setup() {
if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
drawPipe(); // Draw the static parts of the scene
display.display();
}
void loop() {
animateWater(); // Animate the water droplets falling
}
void drawPipe() {
// Draw the pipe
display.drawLine(100, 2, 127, 2, WHITE);
display.drawLine(105, 6, 127, 6, WHITE);
display.drawLine(100, 3, 100, 8, WHITE);
display.drawLine(105, 7, 105, 8, WHITE);
// Draw the conical area
display.drawCircle(80, 40, 20, WHITE);
}
void animateWater() {
// Erase the previous water position
display.fillRect(101, waterPosition, 4, 4, BLACK);
// Increment the water position
waterPosition += 2; // Adjust the speed of falling water here
// Check if water reaches the bottom
if (waterPosition >= 58) {
waterPosition = 0; // Reset water position
}
// Draw the water at the new position
display.fillRect(101, waterPosition, 4, 4, WHITE);
// Display the changes
display.display();
// Introduce a short delay to control animation speed
delay(50); // Adjust the delay for desired animation speed
}