Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
from board import TX, RX, A1
import busio
import digitalio
from adafruit_max7219 import matrices
mosi = TX
clk = RX
cs = digitalio.DigitalInOut(A1)
spi = busio.SPI(clk, MOSI=mosi)
matrix = matrices.Matrix8x8(spi, cs)
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
for i in range(8):
matrix.pixel(1, i, 1)
matrix.show()
time.sleep(0.5)
# now scroll the column to the right
for j in range(8):
matrix.scroll(1, 0)
matrix.show()
time.sleep(0.5)
# show a string one character at a time
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)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import random
from board import TX, RX, A1
import busio
import digitalio
from adafruit_max7219 import bcddigits
mosi = TX
clk = RX
cs = digitalio.DigitalInOut(A1)
spi = busio.SPI(clk, MOSI=mosi)
leds = bcddigits.BCDDigits(spi, cs, nDigits=8)
while True:
# clear display and dim 0
leds.brightness(0)
leds.clear_all()
# place 8-digit number on display
value = 12345678
leds.show_str(0, "{:8}".format(value))
leds.show()
# increase the brightness slowly
for i in range(16):
leds.brightness(i)
time.sleep(0.5)
leds.brightness(3)
# show "-HELP-90" on display
leds.show_str(6, "90") # show 90 starting at position 6
leds.set_digit(0, 10) # show - at position 0
leds.set_digit(1, 12) # show H at position 1
leds.set_digit(2, 11) # show E at position 2
leds.set_digit(3, 13) # show L at position 3
leds.set_digit(4, 14) # show P at position 4
leds.set_digit(5, 10) # show - at position 5
leds.show()
time.sleep(1.0)
leds.clear_all()
leds.brightness(5)
# set the two dots and two 4-digit numbers
leds.show_dot(2, 1)
leds.show_dot(6, 1)
leds.show_str(0, " 72.5")
leds.show_str(4, "-10.8")
leds.show()
time.sleep(1.0)
leds.brightness(10)
leds.clear_all()
# show a 4 character numeric string
leds.show_str(0, " 0")
leds.show()
time.sleep(1.0)
leds.clear_all()
# show 0->8
for digit in range(8):
leds.set_digit(digit, digit)
leds.show()
time.sleep(1.0)
# show random 8-digit numbers via show_str
for _ in range(10):
number = random.uniform(-1.0, 1.0)
number *= 10000.0
number_string = "{:9.3f}".format(number)
leds.clear_all()
leds.show_str(0, number_string)
leds.show()
time.sleep(1.0)
# show the help string
leds.clear_all()
leds.show_help(2)
leds.show()
time.sleep(1.0)
|