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