from machine import Pin, SPI
import machine
import time
import max7219
#// SPI = Serial peripheral interface - system set up so that peripheral devices (sensors, displays) and the microcontroler can communicate
""" In this case its SPI
(1 - bus 1,
baudrate=10000000 - data transfered in bits per second, this case 10Mb
polarity=1 - idle state of clock signal, where 0 is low,
the clock inside goes between 1 and 0 in an on off way, the transition between them is called a clock edge
phase=0 - decides when the data is sampled in relation to the clock, in this case on the first clock edge (the first transition between 1 and 0)
sck = sclk = clk - synchronizes the system clock for sharing data
mosi - master output slave input, in this case the esp32 is the master and the max7219 is the slave.
)"""
spi = SPI(1, baudrate=10000000, polarity=1, phase=0, sck=Pin(4), mosi=Pin(2))
ss = Pin(5, Pin.OUT)
delay = 0.5
text = "TechMo the best"
# in this case its(spi(look above), the GPIO that is connected on chip select(CS) or slave select(SS) of peripheral device, number of chained maxes)
display = max7219.Matrix8x8(spi, ss, 1)
#display = max7219.Matrix8x8(spi, ss, len(text))
#leng = len(text)*6
while True:
for HELP in range(0, len(text) * 8, 8):
# this is the text, x, y, brightness(depends on device, either binary or not))
display.text(text, -HELP, 1, 1)
display.show()
time.sleep(delay)
display.text(text, -HELP, 1, 0)
#display.fill(0) # Turns all pixels to one brightness, in this case all off, .poweroff() can work, if module has it.
display.show()
time.sleep(1)