Simple test

Ensure your device works with this simple test.

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