import random
import time
from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
# Initialize the I2C interface and OLED screen
i2c = I2C(1, scl=Pin(19), sda=Pin(18))
oled = SSD1306_I2C(128, 64, i2c)
# Characters to use in the "rain"
characters = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F']
# Number of columns (depends on your display width and font size)
columns = 128 // 8
# Initialize the positions for each column
positions = [0] * columns
while True:
oled.fill(0) # Clear the display
for i in range(columns):
# Draw each character at the current position
char = random.choice(characters)
oled.text(char, i * 8, positions[i])
# Move the character down
positions[i] += 8
# Randomly reset the position to the top
if positions[i] > 64 or random.random() > 0.9:
positions[i] = 0
oled.show() # Update the display
time.sleep(0.1) # Control the speed of the animation