import max7219
from machine import Pin, SPI
from time import sleep
# Initialize the first SPI
spi1 = SPI(0, baudrate=10000000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(3))
ss1 = Pin(1, Pin.OUT)
# Initialize the second SPI
spi2 = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(10), mosi=Pin(11))
ss2 = Pin(9, Pin.OUT)
# Initialize the third SPI
spi3 = SPI(0, baudrate=10000000, polarity=1, phase=0, sck=Pin(18), mosi=Pin(19)) # Use SPI bus index 0
ss3 = Pin(13, Pin.OUT)
# Define custom symbol bitmaps for each 8x8 grid
symbol_bitmaps = [
#1-4
# Symbol for Matrix 1
[
0b00011000,
0b00111100,
0b01111110,
0b11111111,
0b01111110,
0b00111100,
0b00011000,
0b00000000
],
# Symbol for Matrix 2
[
0b11111111,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b11111111
],
# Symbol for Matrix 3
[
0b01111110,
0b11111111,
0b11011011,
0b11011011,
0b11011011,
0b11111111,
0b01111110,
0b00000000
],
# Symbol for Matrix 4
[
0b00111100,
0b01000010,
0b10000001,
0b10000001,
0b10000001,
0b01000010,
0b00111100,
0b00000000
],
# 5-8
# Symbol for Matrix 5
[
0b00000000,
0b00000000,
0b11111111,
0b11111111,
0b11111111,
0b11111111,
0b00000000,
0b00000000
],
# Symbol for Matrix 6
[
0b11111111,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b10000001,
0b11111111
],
# Symbol for Matrix 7
[
0b01111110,
0b01111110,
0b01111110,
0b01111110,
0b01111110,
0b01111110,
0b01111110,
0b01111110
],
# Symbol for Matrix 8
[
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010
],
#9-12
# Symbol for Matrix 9
[
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010
],
# Symbol for Matrix 10
[
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010
],
# Symbol for Matrix 11
[
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010
],
# Symbol for Matrix 12
[
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010,
0b01010101,
0b10101010
]
]
# Calculate the width of each symbol
symbol_width = 8 # Since each symbol is 8x8
# Initialize the first LED matrix
num_matrices1 = 4
display1 = max7219.Matrix8x8(spi1, ss1, num_matrices1)
display1.brightness(1)
display1.fill(0)
# Initialize the second LED matrix
num_matrices2 = 4
display2 = max7219.Matrix8x8(spi2, ss2, num_matrices2)
display2.brightness(1)
display2.fill(0)
# Initialize the third LED matrix
num_matrices3 = 4
display3 = max7219.Matrix8x8(spi3, ss3, num_matrices3)
display3.brightness(1)
display3.fill(0)
# Display all symbols on the first set of matrices
for matrix_index in range(num_matrices1):
for i in range(8):
for j in range(8):
display1.pixel(i + matrix_index * 8, j, symbol_bitmaps[matrix_index][i] & (1 << (7 - j)))
# Display all symbols on the second set of matrices
for matrix_index in range(num_matrices2):
for i in range(8):
for j in range(8):
display2.pixel(i + matrix_index * 8, j, symbol_bitmaps[matrix_index + num_matrices1][i] & (1 << (7 - j)))
# Display all symbols on the third set of matrices
for matrix_index in range(num_matrices3):
for i in range(8):
for j in range(8):
display3.pixel(i + matrix_index * 8, j, symbol_bitmaps[matrix_index + num_matrices1 + num_matrices2][i] & (1 << (7 - j)))
# Show all displays
display1.show()
display2.show()
display3.show()
sleep(10) # Display for 10 seconds, adjust as needed