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