Skip to content

Commit 05e16d5

Browse files
committed
Added examples to project
1 parent 5ef7f50 commit 05e16d5

File tree

2 files changed

+142
-0
lines changed

2 files changed

+142
-0
lines changed

examples/showbcddigits.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import time
2+
import random
3+
from board import TX, RX, A2
4+
import busio
5+
import digitalio
6+
from adafruit_max7219 import bcddigits
7+
8+
mosi = TX
9+
clk = RX
10+
cs = digitalio.DigitalInOut(A2)
11+
12+
spi = busio.SPI(clk, MOSI=mosi)
13+
14+
leds = bcddigits.BCDDigits(spi, cs, nDigits=8)
15+
while True:
16+
# clear display and dim 0
17+
leds.brightness(0)
18+
leds.clear_all()
19+
20+
# place 8-digit number on display
21+
value = 12345678
22+
leds.show_str(0, '{:8}'.format(value))
23+
leds.show()
24+
25+
# increase the brightness slowly
26+
for i in range(16):
27+
leds.brightness(i)
28+
time.sleep(0.5)
29+
30+
leds.brightness(3)
31+
32+
# show "-HELP-90" on display
33+
leds.show_str(6, '90') # show 90 starting at position 6
34+
leds.set_digit(0, 10) # show - at position 0
35+
leds.set_digit(1, 12) # show H at position 1
36+
leds.set_digit(2, 11) # show E at position 2
37+
leds.set_digit(3, 13) # show L at position 3
38+
leds.set_digit(4, 14) # show P at position 4
39+
leds.set_digit(5, 10) # show - at position 5
40+
41+
leds.show()
42+
time.sleep(1.0)
43+
44+
leds.clear_all()
45+
leds.brightness(5)
46+
47+
# set the two dots and two 4-digit numbers
48+
leds.show_dot(2, 1)
49+
leds.show_dot(6, 1)
50+
leds.show_str(0, ' 72.5')
51+
leds.show_str(4, '-10.8')
52+
53+
leds.show()
54+
time.sleep(1.0)
55+
56+
leds.brightness(10)
57+
leds.clear_all()
58+
# show a 4 character numeric string
59+
leds.show_str(0, ' 0')
60+
leds.show()
61+
time.sleep(1.0)
62+
63+
leds.clear_all()
64+
# show 0->8
65+
for digit in range(8):
66+
leds.set_digit(digit, digit)
67+
68+
leds.show()
69+
time.sleep(1.0)
70+
71+
# show random 8-digit numbers via show_str
72+
for _ in range(10):
73+
number = random.uniform(-1.0, 1.0)
74+
number *= 10000.0
75+
number_string = '{:9.3f}'.format(number)
76+
leds.clear_all()
77+
leds.show_str(0, number_string)
78+
leds.show()
79+
time.sleep(1.0)
80+
81+
# show the help string
82+
leds.clear_all()
83+
leds.show_help(2)
84+
leds.show()
85+
86+
time.sleep(1.0)

examples/showmatrix.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import time
2+
from board import TX, RX, A2
3+
import busio
4+
import digitalio
5+
from adafruit_max7219 import matrices
6+
7+
mosi = TX
8+
clk = RX
9+
cs = digitalio.DigitalInOut(A2)
10+
11+
spi = busio.SPI(clk, MOSI=mosi)
12+
13+
matrix = matrices.Matrix8x8(spi, cs)
14+
while True:
15+
print("Cycle start")
16+
# all lit up
17+
matrix.fill(True)
18+
matrix.show()
19+
time.sleep(0.5)
20+
21+
# all off
22+
matrix.fill(False)
23+
matrix.show()
24+
time.sleep(0.5)
25+
26+
# one column of leds lit
27+
for i in range(8):
28+
matrix.pixel(1, i, 1)
29+
matrix.show()
30+
time.sleep(0.5)
31+
# now scroll the column to the right
32+
for j in range(8):
33+
matrix.scroll(1, 0)
34+
matrix.show()
35+
time.sleep(0.5)
36+
37+
# show a string one character at a time
38+
adafruit = 'Adafruit'
39+
for char in adafruit:
40+
matrix.fill(0)
41+
matrix.text(char, 0, 0)
42+
matrix.show()
43+
time.sleep(1.0)
44+
45+
# scroll the last character off the display
46+
for i in range(8):
47+
matrix.scroll(-1, 0)
48+
matrix.show()
49+
time.sleep(0.5)
50+
51+
# scroll a string across the display
52+
for pixel_position in range(len(adafruit) * 8):
53+
matrix.fill(0)
54+
matrix.text(adafruit, -pixel_position, 0)
55+
matrix.show()
56+
time.sleep(0.25)

0 commit comments

Comments
 (0)