import time
from machine import SPI, Pin
import max7219
# SPI0 Configuration
spi = SPI(0, baudrate=1000000, polarity=0, phase=0, sck=Pin(18), mosi=Pin(19))
cs = Pin(15, Pin.OUT)
# Initialize the MAX7219 matrix display
display = max7219.Matrix8x8(spi, cs)
# Set brightness
display.brightness(8)
# Clear the display
display.fill(0)
display.show()
# Define a set of symbols as 8x8 patterns
symbols = [
# Smiley face
[0b00111100,
0b01000010,
0b10100101,
0b10000001,
0b10100101,
0b10011001,
0b01000010,
0b00111100],
# Heart
[0b00000000,
0b01100110,
0b11111111,
0b11111111,
0b01111110,
0b00111100,
0b00011000,
0b00000000],
# Circle
[0b00111100,
0b01111110,
0b11111111,
0b11100111,
0b11100111,
0b11111111,
0b01111110,
0b00111100],
# X mark
[0b10000001,
0b01000010,
0b00100100,
0b00011000,
0b00011000,
0b00100100,
0b01000010,
0b10000001],
# Plus Sign
[0b00011000,
0b00011000,
0b00011000,
0b11111111,
0b11111111,
0b00011000,
0b00011000,
0b00011000],
]
# Function to display a symbol on the 8x8 matrix
def display_symbol(symbol):
display.fill(0) # Clear the display before drawing a new symbol
for y, row in enumerate(symbol):
for x in range(8): # Loop through each bit in the row (8 bits per row)
if row & (1 << (7 - x)): # Check if the bit is 1
display.pixel(x, y, 1) # Turn on the pixel at (x, y)
display.show()
# Continuously display all symbols in a loop
while True:
for symbol in symbols: # Iterate through all defined symbols
display_symbol(symbol) # Display the current symbol
time.sleep(1) # Wait for 1 second before showing the next symbol