#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define stars 20
#define trajectory_length 5
float velocity[stars];
float x1[stars]; // počáteční
float x2[stars]; // koncová
float y[stars];
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.display();
Serial.begin(9600);
/*
for (int a = 0; a < stars; a++) {
y[a] = random(0, SCREEN_HEIGHT);
}
*/
for (int a = 0; a < stars; a++) {
x1[a] = random(0, SCREEN_WIDTH);
}
for (int a = 0; a < stars; a++) {
x2[a] = random(0, SCREEN_WIDTH);
}
for (int a = 0; a < stars; a++) {
velocity[a] = random(100, 200) / 100.0;
}
}
void loop() {
display.clearDisplay();
for (int b = 0; b < stars; b++) {
// display.drawPixel(x1[b], y[b], WHITE);
display.drawLine(x1[b],y[b],x2[b],y[b]-trajectory_length,WHITE);
y[b]=y[b]+velocity[b]; // posun v ose Y dolů - padání
if ( y[b] > SCREEN_HEIGHT) {y[b] = 0;
x1[b] = random(0, SCREEN_WIDTH);
x2[b] = random(x1[b], x1[b]+trajectory_length);
velocity[b] = random(100, 200) / 100.0;
}
}
display.display();
delay(1);
}