#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int NUM_PARTICLES = 20;
float particle_x[NUM_PARTICLES];
float particle_y[NUM_PARTICLES];
int particle_speed_x[NUM_PARTICLES];
int particle_speed_y[NUM_PARTICLES];
float particle_size[NUM_PARTICLES];
int init_spread = 15;
int time_value = 0;
void setup(void) {
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;)
;
}
display.display(); // Display the splash screen
delay(2000);
display.clearDisplay(); // Clear the buffer
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
for (int i = 0; i < NUM_PARTICLES; i++) {
particle_x[i] = random(64 - init_spread, 64 + init_spread);
particle_y[i] = random(32 - init_spread, 32 + init_spread);
particle_speed_x[i] = random(-5, 6) * 3;
particle_speed_y[i] = random(-5, 6) * 3;
particle_size[i] = 8;
}
}
void loop(void) {
display.clearDisplay();
// draw particles --------------
for (int i = 0; i < NUM_PARTICLES; i++) {
particle_x[i] = particle_x[i] + particle_speed_x[i] / 10.0;
particle_y[i] = particle_y[i] + particle_speed_y[i] / 10.0;
particle_size[i] = particle_size[i] * 0.95;
display.drawCircle(particle_x[i], particle_y[i], particle_size[i], SSD1306_WHITE);
if ((particle_x[i] > SCREEN_WIDTH) || (particle_x[i] < 0) || (particle_y[i] > SCREEN_HEIGHT) || (particle_y[i] < 0) || (particle_size[i] < 0.5)) {
particle_x[i] = random(64 - init_spread, 64 + init_spread);
particle_y[i] = random(32 - init_spread, 32 + init_spread);
particle_speed_x[i] = random(-5, 6) * 3;
particle_speed_y[i] = random(-5, 6) * 3;
particle_size[i] = 8;
}
}
// draw big circle in the middle --------------
byte radius = round(25.0 + sin(time_value / 10.0) * 2.0);
display.fillCircle(64, 32, radius, SSD1306_WHITE);
// draw big value in the center --------------
display.setTextColor(SSD1306_BLACK);
display.setTextSize(2);
display.setCursor(56, 27);
display.print("Hi"); // Replace with your charge value
display.display();
delay(100);
}
Loading
ssd1306
ssd1306