# Import MicroPython libraries of PIN and SPI
from machine import Pin, SPI
# Import MicoPython max7219 library
import max7219
# Import time
import time
"""
>>> from machine import Pin, SPI
>>> from max7219 import Max7219
>>> spi = SPI(1, baudrate=10000000)
>>> screen = Max7219(32, 16, spi, Pin(15))
>>> screen.rect(0, 0, 32, 16, 1) # Draws a frame
>>> screen.text('Hi!', 4, 4, 1)
>>> screen.show()
"""
#Intialize the SPI
spi = SPI(0, baudrate=10000000, polarity=1, phase=0, sck=Pin(2), mosi=Pin(3))
ss = Pin(5, Pin.OUT)
# Create matrix display instant, which has four MAX7219 devices.
display = max7219.Max7219(32,8,spi, ss,rotate_180=True)
display.text('1234',0,0,1)
display.show()
time.sleep(1)
#Set the display brightness. Value is 1 to 15.
display.brightness(10)
#Define the scrolling message
scrolling_message = "RASPBERRY PI PICO AND MAX7219 -- 8x8 DOT MATRIX SCROLLING DISPLAY"
#Get the message length
length = len(scrolling_message)
#Calculate number of columns of the message
column = (length * 8)
#Clear the display.
display.fill(0)
display.show()
#sleep for one one seconds
time.sleep(1)
# Unconditionally execute the loop
while True:
for x in range(32, -column, -1):
#Clear the display
display.fill(0)
# Write the scrolling text in to frame buffer
display.text(scrolling_message ,x,0,1)
#Show the display
display.show()
#Set the Scrolling speed. Here it is 50mS.
time.sleep(0.05)