# Matrix 8x8
# D1 (GPIO2) ----- CLK
# D2 (GPIO1) ----- CS
# D3 (GPIO3) ----- DIN
# 3V3 ------------ VCC
# GND ------------ GND
import max7219, time
from machine import Pin,SPI
spi = SPI(0, baudrate=80000, sck=Pin(2), mosi=Pin(3), miso=Pin(0))
cs = Pin(1, Pin.OUT)
matrix = max7219.Matrix8x8(spi, cs, 4)
matrix.text('pico',0,0,1)
matrix.show()
time.sleep(3)
while True:
print("Cycle start")
# all lit up
matrix.fill(True)
matrix.show()
time.sleep(0.5)
# all off
matrix.fill(False)
matrix.show()
time.sleep(0.5)
# one column of leds lit
print("--- one column ---")
for i in range(8):
matrix.pixel(1, i, 1)
print(i)
matrix.show()
time.sleep(0.5)
# now scroll the column to the right
print("--- scroll the column ---")
for j in range(8):
print(j)
matrix.scroll(1, 0)
matrix.show()
time.sleep(0.5)
# show a string one character at a time
print("--- show a string ---")
adafruit = "Adafruit"
for char in adafruit:
matrix.fill(0)
matrix.text(char, 0, 0)
matrix.show()
time.sleep(1.0)
# scroll the last character off the display
for i in range(8):
matrix.scroll(-1, 0)
matrix.show()
time.sleep(0.5)
# scroll a string across the display
for pixel_position in range(len(adafruit) * 8):
matrix.fill(0)
matrix.text(adafruit, -pixel_position, 0)
matrix.show()
time.sleep(0.25)