from machine import Pin, SPI
import max7219 from Matrix8x8
import time
# Initialize SPI communication
spi = SPI(0, baudrate=10000000, polarity=1, phase=0, sck=Pin(18), mosi=Pin(23))
# Define pins for the CS (Chip Select) lines for each display
cs_pins = [Pin(pin, Pin.OUT) for pin in [5, 17, 16, 4]] # Example pins, adjust as needed
# Create Matrix8x8 instances for each display
displays = [max7219.Matrix8x8(spi, cs) for cs in cs_pins]
# Set brightness for all displays
for display in displays:
display.brightness(5)
# Define your scrolling messages
scrolling_messages = [
"HELLO WORLD!",
"MICROPYTHON ROCKS!",
"MAX7219 DEMO!",
"HAVE A NICE DAY!"
]
# Loop through each display and show scrolling messages
for i, message in enumerate(scrolling_messages):
# Clear all displays
for display in displays:
display.fill(0)
display.show()
# Calculate message length and columns
length = len(message)
columns = length * 8
# Display the message on each display
for j, display in enumerate(displays):
x_offset = j * 8 # Adjust the x offset based on display position
for x in range(columns, -8, -1):
display.fill(0) # Clear the display
display.text(message, x + x_offset, 0, 1) # Display text
display.show() # Show the display
time.sleep(0.1) # Adjust the scrolling speed
# Clear all displays after displaying all messages
for display in displays:
display.fill(0)
display.show()