/*
https://www.reddit.com/user/Some-Background6188/
https://www.reddit.com/r/arduino/comments/1m8i587/nano_matrix/
*/
#include <Wire.h>
#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);
const int charWidth = 6;
const int charHeight = 8;
const int columns = SCREEN_WIDTH / charWidth;
float drops[columns]; // Use float for smooth movement
void setup() {
// Initialize display
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.display();
randomSeed(analogRead(A0));
// Initialize drops with random starting positions
for(int i = 0; i < columns; i++) {
drops[i] = random(-20.0, 0.0);
}
}
char randomChar() {
// Matrix-style characters
const char chars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
return chars[random(0, sizeof(chars) - 1)];
}
void loop() {
display.clearDisplay();
for(int i = 0; i < columns; i++) {
int x = i * charWidth;
int y = (int)(drops[i] * charHeight);
// Only draw if within screen bounds
if (y >= 0 && y < SCREEN_HEIGHT) {
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE); // It won't display without this line
display.setCursor(x, y);
display.print(randomChar()); // put a character to screen
}
// Move drop down smoothly
drops[i] += 0.2; // Smaller increment for smoother movement
// Reset drop when it goes off screen
if(drops[i] * charHeight > SCREEN_HEIGHT + charHeight) {
if(random(0, 100) > 85) {
drops[i] = random(-10.0, 0.0);
}
}
}
display.display();
delay(50); // Faster refresh for smoother animation
}