from machine import Pin, I2C
import ssd1306
import time
# I2C setup for ESP32
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=400000)
# OLED setup
WIDTH = 128
HEIGHT = 64
oled = ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c)
# Easy-to-edit messages
TITLE = "ESP32 DISPLAY"
STATIC_LINE = "OLED scrolling demo"
SCROLL_MESSAGE = "Welcome to Computer Engineering! ESP32 + OLED scrolling project "
FOOTER = "By: Pendar"
def show_start_screen():
oled.fill(0)
oled.text(TITLE, 0, 0)
oled.text(STATIC_LINE, 0, 16)
oled.text("Loading...", 0, 32)
oled.text(FOOTER, 0, 48)
oled.show()
time.sleep(2)
def scroll_text(message, y_pos=30, speed=0.03):
text_width = len(message) * 8 # approx. 8 pixels per character
for x in range(WIDTH, -text_width, -1):
oled.fill(0)
oled.text(TITLE, 0, 0)
oled.text("Message:", 0, 16)
oled.text(message, x, y_pos)
oled.text(FOOTER, 0, 48)
oled.show()
time.sleep(speed)
def main():
show_start_screen()
while True:
scroll_text(SCROLL_MESSAGE)
main()