# Running Text ESP32 + MAX7219 - Wokwi MicroPython
# Configuration: chain=4, layout=parola, rotate=0
# ESP32: GPIO23->DIN, GPIO18->CLK, GPIO5->CS
# No external max7219.py is needed.
from machine import Pin, SPI
import framebuf
import time
MODULES = 4
WIDTH = MODULES * 8
SPEED_MS = 150 # More milliseconds = slower movement
PAUSE_MS = 2000
BRIGHTNESS = 3 # 0..15
MESSAGE = (
"SELAMAT DATANG DI PRODI STI, FATEK, "
"UMMAT"
)
spi = SPI(2, baudrate=1000000, polarity=0, phase=0,
sck=Pin(18), mosi=Pin(23))
cs = Pin(5, Pin.OUT, value=1)
# Logical coordinates: x=0 is LEFT, y=0 is TOP.
pixels = bytearray(WIDTH * 8)
screen = framebuf.FrameBuffer(pixels, WIDTH, 8, framebuf.MONO_HLSB)
def broadcast(register, value):
cs.value(0)
spi.write(bytes((register, value)) * MODULES)
cs.value(1)
def show():
packet = bytearray(MODULES*2)
for row in range(8):
for module in range(MODULES):
#Pertahankan koreksi atas-bawah
packet[2 * module] = 8 - row
#Perbaiki urutan modul: ITS menjadi STI
packet[2 * module + 1] = (pixels[row*MODULES+(MODULES-1-module)])
cs.value(0)
spi.write(packet)
cs.value(1)
# Initialize MAX7219 chips.
broadcast(0x0C, 0) # shutdown for setup
broadcast(0x0F, 0) # disable display test
broadcast(0x09, 0) # no BCD decode
broadcast(0x0B, 7) # scan all 8 rows
broadcast(0x0A, BRIGHTNESS) # brightness
broadcast(0x0C, 1) # normal operation
screen.fill(0)
show()
# A short, readable test before scrolling.
print("TES ORIENTASI: STI")
screen.text("STI", 0, 0, 1)
show()
time.sleep_ms(3000)
print("RUNNING TEXT: KANAN -> KIRI")
print("Kecepatan:", SPEED_MS, "ms per piksel")
while True:
# x decreases by one pixel: the text moves from RIGHT to LEFT.
for x in range(WIDTH, -(len(MESSAGE) * 8) - 1, -1):
screen.fill(0)
screen.text(MESSAGE, x, 0, 1)
show()
time.sleep_ms(SPEED_MS)
screen.fill(0)
show()
time.sleep_ms(PAUSE_MS)