Skip to content

Commit a76511f

Browse files
authored
Merge pull request #13 from ladyada/master
Add support for the charlie bonnet
2 parents 80cfa10 + 3caf17c commit a76511f

File tree

7 files changed

+145
-107
lines changed

7 files changed

+145
-107
lines changed

adafruit_is31fl3731.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,16 @@ def pixel_addr(x, y):
353353
else:
354354
y = 7 - y
355355
return x * 16 + y
356+
357+
358+
class CharlieBonnet(Matrix):
359+
"""Supports the Charlieplexed bonnet"""
360+
width = 16
361+
height = 8
362+
363+
@staticmethod
364+
def pixel_addr(x, y):
365+
"""Calulate the offset into the device array for x,y pixel"""
366+
if x >= 8:
367+
return (x-6) * 16 - (y + 1)
368+
return (x+1) * 16 + (7 - y)

examples/blink.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,28 @@
22
import board
33
import adafruit_is31fl3731
44

5+
i2c = busio.I2C(board.SCL, board.SDA)
6+
57
# array pattern in bits; top row-> bottom row, 8 bits in each row
68
an_arrow = bytearray((0x08, 0x0c, 0xfe, 0xff, 0xfe, 0x0c, 0x08, 0x00, 0x00))
79

8-
with busio.I2C(board.SCL, board.SDA) as i2c:
9-
# initial display using Feather CharlieWing LED 15 x 7
10-
display = adafruit_is31fl3731.CharlieWing(i2c)
11-
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
12-
#display = adafruit_is31fl3731.Matrix(i2c)
10+
# initial display using Feather CharlieWing LED 15 x 7
11+
display = adafruit_is31fl3731.CharlieWing(i2c)
12+
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
13+
#display = adafruit_is31fl3731.Matrix(i2c)
14+
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
15+
#display = adafruit_is31fl3731.CharlieBonnet(i2c)
1316

14-
# first load the frame with the arrows; moves the an_arrow to the right in each
15-
# frame
16-
display.sleep(True) # turn display off while updating blink bits
17-
display.fill(50)
18-
for y in range(display.height):
19-
row = an_arrow[y]
20-
for x in range(8):
21-
bit = 1 << (7-x) & row
22-
if bit:
23-
display.pixel(x + 4, y, None, blink=True)
17+
# first load the frame with the arrows; moves the an_arrow to the right in each
18+
# frame
19+
display.sleep(True) # turn display off while updating blink bits
20+
display.fill(0)
21+
for y in range(display.height):
22+
row = an_arrow[y]
23+
for x in range(8):
24+
bit = 1 << (7-x) & row
25+
if bit:
26+
display.pixel(x + 4, y, 50, blink=True)
2427

25-
display.blink(300) # ranges from 270 to 2159; smaller the number to faster blink
26-
display.sleep(False) # turn display on
28+
display.blink(1000) # ranges from 270 to 2159; smaller the number to faster blink
29+
display.sleep(False) # turn display on

examples/frame.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,35 @@
33
import busio
44
import adafruit_is31fl3731
55

6+
i2c = busio.I2C(board.SCL, board.SDA)
7+
68
# arrow pattern in bits; top row-> bottom row, 8 bits in each row
79
arrow = bytearray((0x08, 0x0c, 0xfe, 0xff, 0xfe, 0x0c, 0x08, 0x00, 0x00))
810

9-
with busio.I2C(board.SCL, board.SDA) as i2c:
10-
# initial display using Feather CharlieWing LED 15 x 7
11-
display = adafruit_is31fl3731.CharlieWing(i2c)
12-
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
13-
#display = adafruit_is31fl3731.Matrix(i2c)
11+
# initial display using Feather CharlieWing LED 15 x 7
12+
display = adafruit_is31fl3731.CharlieWing(i2c)
13+
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
14+
#display = adafruit_is31fl3731.Matrix(i2c)
15+
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
16+
#display = adafruit_is31fl3731.CharlieBonnet(i2c)
17+
1418

15-
# first load the frame with the arrows; moves the arrow to the right in each
16-
# frame
17-
display.sleep(True) # turn display off while frames are updated
19+
# first load the frame with the arrows; moves the arrow to the right in each
20+
# frame
21+
display.sleep(True) # turn display off while frames are updated
22+
for frame in range(8):
23+
display.frame(frame, show=False)
24+
display.fill(0)
25+
for y in range(display.height):
26+
row = arrow[y]
27+
for x in range(8):
28+
bit = 1 << (7-x) & row
29+
# display the pixel into selected frame with varying intensity
30+
if bit:
31+
display.pixel(x + frame, y, frame**2 + 1)
32+
display.sleep(False)
33+
# now tell the display to show the frame one at time
34+
while True:
1835
for frame in range(8):
19-
display.frame(frame, show=False)
20-
display.fill(0)
21-
for y in range(display.height):
22-
row = arrow[y]
23-
for x in range(8):
24-
bit = 1 << (7-x) & row
25-
# display the pixel into selected frame with varying intensity
26-
if bit:
27-
display.pixel(x + frame, y, frame**2 + 1)
28-
display.sleep(False)
29-
# now tell the display to show the frame one at time
30-
while True:
31-
for frame in range(8):
32-
display.frame(frame)
33-
time.sleep(.1)
36+
display.frame(frame)
37+
time.sleep(.1)

examples/is31fl3731_simpletest.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22
import busio
33
import adafruit_is31fl3731
44

5+
i2c = busio.I2C(board.SCL, board.SDA)
56

6-
with busio.I2C(board.SCL, board.SDA) as i2c:
7-
# initialize display using Feather CharlieWing LED 15 x 7
8-
display = adafruit_is31fl3731.CharlieWing(i2c)
9-
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
10-
#display = adafruit_is31fl3731.Matrix(i2c)
7+
# initialize display using Feather CharlieWing LED 15 x 7
8+
display = adafruit_is31fl3731.CharlieWing(i2c)
119

12-
# draw a box on the display
13-
# first draw the top and bottom edges
14-
for x in range(display.width):
15-
display.pixel(x, 0, 50)
16-
display.pixel(x, display.height - 1, 50)
17-
# now draw the left and right edges
18-
for y in range(display.height):
19-
display.pixel(0, y, 50)
20-
display.pixel(display.width - 1, y, 50)
10+
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
11+
#display = adafruit_is31fl3731.Matrix(i2c)
12+
13+
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
14+
#display = adafruit_is31fl3731.CharlieBonnet(i2c)
15+
16+
# draw a box on the display
17+
# first draw the top and bottom edges
18+
for x in range(display.width):
19+
display.pixel(x, 0, 50)
20+
display.pixel(x, display.height - 1, 50)
21+
# now draw the left and right edges
22+
for y in range(display.height):
23+
display.pixel(0, y, 50)
24+
display.pixel(display.width - 1, y, 50)

examples/text.py

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
import board
22
import busio
3-
import framebuf
3+
import adafruit_framebuf
44
import adafruit_is31fl3731
55

6-
buf = bytearray(32)
7-
8-
with busio.I2C(board.SCL, board.SDA) as i2c:
9-
# initial display using Feather CharlieWing LED 15 x 7
10-
display = adafruit_is31fl3731.CharlieWing(i2c)
11-
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
12-
#display = adafruit_is31fl3731.Matrix(i2c)
13-
14-
fb = framebuf.FrameBuffer(buf, display.width, display.height, framebuf.MONO_VLSB)
15-
text_to_show = "Adafruit!!"
16-
frame = 0 # start with frame 0
17-
while True:
18-
for i in range(len(text_to_show) * 9):
19-
fb.fill(0)
20-
fb.text(text_to_show, -i + display.width, 0)
21-
22-
# to improve the display flicker we can use two frame
23-
# fill the next frame with scrolling text, then
24-
# show it.
25-
display.frame(frame, show=False)
26-
# turn all LEDs off
27-
display.fill(0)
28-
for x in range(display.width):
29-
# using the FrameBuffer text result
30-
bite = buf[x]
31-
for y in range(display.height):
32-
bit = 1 << y & bite
33-
# if bit > 0 then set the pixel brightness
34-
if bit:
35-
display.pixel(x, y, 50)
36-
37-
# now that the frame is filled, show it.
38-
display.frame(frame, show=True)
39-
frame = 0 if frame else 1
6+
7+
i2c = busio.I2C(board.SCL, board.SDA)
8+
9+
# initial display using Feather CharlieWing LED 15 x 7
10+
#display = adafruit_is31fl3731.CharlieWing(i2c)
11+
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
12+
#display = adafruit_is31fl3731.Matrix(i2c)
13+
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
14+
display = adafruit_is31fl3731.CharlieBonnet(i2c)
15+
16+
text_to_show = "Adafruit!!"
17+
18+
# Create a framebuffer for our display
19+
buf = bytearray(32) # 2 bytes tall x 16 wide = 32 bytes (9 bits is 2 bytes)
20+
fb = adafruit_framebuf.FrameBuffer(buf, display.width, display.height, adafruit_framebuf.MVLSB)
21+
22+
23+
frame = 0 # start with frame 0
24+
while True:
25+
for i in range(len(text_to_show) * 9):
26+
fb.fill(0)
27+
fb.text(text_to_show, -i + display.width, 0, color=1)
28+
29+
# to improve the display flicker we can use two frame
30+
# fill the next frame with scrolling text, then
31+
# show it.
32+
display.frame(frame, show=False)
33+
# turn all LEDs off
34+
display.fill(0)
35+
for x in range(display.width):
36+
# using the FrameBuffer text result
37+
bite = buf[x]
38+
for y in range(display.height):
39+
bit = 1 << y & bite
40+
# if bit > 0 then set the pixel brightness
41+
if bit:
42+
display.pixel(x, y, 50)
43+
44+
# now that the frame is filled, show it.
45+
display.frame(frame, show=True)
46+
frame = 0 if frame else 1

examples/wave.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,31 @@
22
import busio
33
import adafruit_is31fl3731
44

5+
i2c = busio.I2C(board.SCL, board.SDA)
56

67
sweep = [1, 2, 3, 4, 6, 8, 10, 15, 20, 30, 40, 60, 60, 40, 30, 20, 15, 10, 8, 6, 4, 3, 2, 1]
78

89
frame = 0
9-
with busio.I2C(board.SCL, board.SDA) as i2c:
10-
# initialize display using Feather CharlieWing LED 15 x 7
11-
display = adafruit_is31fl3731.CharlieWing(i2c)
12-
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
13-
#display = adafruit_is31fl3731.Matrix(i2c)
1410

15-
while True:
16-
for incr in range(24):
17-
# to reduce update flicker, use two frames
18-
# make a frame active, don't show it yet
19-
display.frame(frame, show=False)
20-
# fill the display with the next frame
21-
for x in range(display.width):
22-
for y in range(display.height):
23-
display.pixel(x, y, sweep[(x+y+incr)%24])
24-
# show the next frame
25-
display.frame(frame, show=True)
26-
frame = 0 if frame else 1
11+
# initialize display using Feather CharlieWing LED 15 x 7
12+
display = adafruit_is31fl3731.CharlieWing(i2c)
13+
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
14+
#display = adafruit_is31fl3731.Matrix(i2c)
15+
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
16+
#display = adafruit_is31fl3731.CharlieBonnet(i2c)
17+
18+
while True:
19+
for incr in range(24):
20+
# to reduce update flicker, use two frames
21+
# make a frame active, don't show it yet
22+
display.frame(frame, show=False)
23+
# fill the display with the next frame
24+
for x in range(display.width):
25+
for y in range(display.height):
26+
display.pixel(x, y, sweep[(x+y+incr)%24])
27+
# show the next frame
28+
display.frame(frame, show=True)
29+
if frame:
30+
frame = 0
31+
else:
32+
frame = 1

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Adafruit-Blinka
1+
Adafruit-Blinka
2+
adafruit-circuitpython-framebuf

0 commit comments

Comments
 (0)