'''
Demonstrates the use of MAX7219, Scrolling display.
* Demonstrate to display the scrolling display.
* Four numbers of the MAX7219 are connected in daisy chain.
* 8x8 dot matrix module, (64 LEDs) is connected with each MAX7219
* totally 8x8x4 = 256 LEDs forming with 8 rows of 32 columns Display area.
* The Raspberry Pi Pico pin connections are MAX7219 given below:
* MAX7219 VCC pin to VBUS
* MAX7219 GND pin to GND
* MAX7219 DIN pin to digital GPIO3
* MAX7219 CS pin to digital GPIO5
* MAX7219 CLOCK pin to digital GPIO2
Name:- M.Pugazhendi
Date:- 10thJul2021
Version:- V0.1
e-mail:- [email protected]
'''
# Import MicroPython libraries of PIN and SPI
from machine import Pin, SPI
# Import MicoPython max7219 library
import max7219
# Import time
import time
#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.Matrix8x8(spi, ss, 4)
#Set the display brightness. Value is 1 to 15.
display.brightness(1)
#Define the scrolling message
scrolling_message = "test"
#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)
# Initial positions of LEDs
led1PosX, led1PosY = 0, 0
led2PosX, led2PosY = 1, 0
def set_led(x, y):
display.pixel(x, y, 1)
def clear_display():
display.fill(0)
display.show()
# Unconditionally execute the loop
while True:
clear_display()
set_led(led1PosX, led1PosY)
set_led(led2PosX, led2PosY)
display.show()
time.sleep(0.2)
# Move LEDs
led1PosX += 1
led2PosX += 1
# Check if LEDs need to move to the next row
if led1PosX == 8 and led1PosY < 8:
led1PosX = 0
led1PosY += 1
if led2PosX == 8 and led2PosY < 8:
led2PosX = 0
led2PosY += 1
# Check if LEDs need to jump to the next section
if led1PosY == 8:
led1PosX = 8
led1PosY = 0
if led2PosY == 8:
led2PosX = 8
led2PosY = 0
# Wrap around if necessary
if led1PosX == 16 and led1PosY < 8:
led1PosX = 8
led1PosY += 1
if led2PosX == 16 and led2PosY < 8:
led2PosX = 8
led2PosY += 1
# Ensure LEDs stay within bounds
if led1PosY == 8:
led1PosY = 0
if led2PosY == 8:
led2PosY = 0
# Restart pattern after reaching the end
if led1PosX == 14 and led1PosY == 7 and led2PosX == 15 and led2PosY == 7:
clear_display()
set_led(led1PosX, led1PosY)
set_led(led2PosX, led2PosY)
display.show()
time.sleep(0.2)
led1PosX, led1PosY = 0, 0
led2PosX, led2PosY = 1, 0
print("Restart")