#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
#include <math.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
}
void loop() {
const int NUM_DOTS = 50;
float dotX[NUM_DOTS];
float dotY[NUM_DOTS];
float dotDX[NUM_DOTS];
float dotDY[NUM_DOTS];
// Initialize dot positions and velocities
for (int i = 0; i < NUM_DOTS; i++) {
float angle = random(360) * PI / 180.0;
dotX[i] = SCREEN_WIDTH / 2.0;
dotY[i] = SCREEN_HEIGHT / 2.0;
dotDX[i] = cos(angle);
dotDY[i] = sin(angle);
}
while (true) {
// Clear the screen
display.clearDisplay();
// Move and draw each dot
for (int i = 0; i < NUM_DOTS; i++) {
// Move the dot
dotX[i] += dotDX[i];
dotY[i] += dotDY[i];
// Check if the dot has gone off the screen
if (dotX[i] < 0 || dotX[i] >= SCREEN_WIDTH || dotY[i] < 0 || dotY[i] >= SCREEN_HEIGHT) {
float angle = random(360) * PI / 180.0;
dotX[i] = SCREEN_WIDTH / 2.0;
dotY[i] = SCREEN_HEIGHT / 2.0;
dotDX[i] = cos(angle);
dotDY[i] = sin(angle);
}
// Draw the dot
display.drawPixel(round(dotX[i]), round(dotY[i]), WHITE);
}
display.display();
delay(50);
}
}