from machine import Pin, SPI
import max7219
from time import sleep
print(max7219)
# SPI setup
spi = SPI(1, baudrate=10000000, polarity=0, phase=0,
sck=Pin(18), mosi=Pin(23), miso=Pin(19)) # miso not used but required for SPI
cs = Pin(5, Pin.OUT)
display = max7219.Matrix8x8(spi, cs, 1)
display.brightness(5)
# ==== Button Setup ====
button = Pin(14, Pin.IN, Pin.PULL_UP) # Button between IO14 and GND
# ===== Rotary Encoder Setup =====
clk = Pin(32, Pin.IN, Pin.PULL_UP)
dt = Pin(33, Pin.IN, Pin.PULL_UP)
# Letters to cycle through
letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']
index = 0
def show_letter(letter):
display.fill(0)
display.text(letter, 0, 0, 1)
display.show()
# Show initial letter
show_letter(letters[index])
# ===== Main Loop =====
last_clk = clk.value()
while True:
current_clk = clk.value()
if current_clk != last_clk:
if dt.value() != current_clk:
index = (index + 1) % len(letters) # Clockwise
else:
index = (index - 1) % len(letters) # Counterclockwise
show_letter(letters[index])
last_clk = current_clk