Skip to content

Commit

Permalink
Merge pull request #13 from ladyada/master
Browse files Browse the repository at this point in the history
Add support for the charlie bonnet
  • Loading branch information
ladyada authored Feb 22, 2019
2 parents 80cfa10 + 3caf17c commit a76511f
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 107 deletions.
13 changes: 13 additions & 0 deletions adafruit_is31fl3731.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,16 @@ def pixel_addr(x, y):
else:
y = 7 - y
return x * 16 + y


class CharlieBonnet(Matrix):
"""Supports the Charlieplexed bonnet"""
width = 16
height = 8

@staticmethod
def pixel_addr(x, y):
"""Calulate the offset into the device array for x,y pixel"""
if x >= 8:
return (x-6) * 16 - (y + 1)
return (x+1) * 16 + (7 - y)
37 changes: 20 additions & 17 deletions examples/blink.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@
import board
import adafruit_is31fl3731

i2c = busio.I2C(board.SCL, board.SDA)

# array pattern in bits; top row-> bottom row, 8 bits in each row
an_arrow = bytearray((0x08, 0x0c, 0xfe, 0xff, 0xfe, 0x0c, 0x08, 0x00, 0x00))

with busio.I2C(board.SCL, board.SDA) as i2c:
# initial display using Feather CharlieWing LED 15 x 7
display = adafruit_is31fl3731.CharlieWing(i2c)
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.Matrix(i2c)
# initial display using Feather CharlieWing LED 15 x 7
display = adafruit_is31fl3731.CharlieWing(i2c)
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.Matrix(i2c)
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.CharlieBonnet(i2c)

# first load the frame with the arrows; moves the an_arrow to the right in each
# frame
display.sleep(True) # turn display off while updating blink bits
display.fill(50)
for y in range(display.height):
row = an_arrow[y]
for x in range(8):
bit = 1 << (7-x) & row
if bit:
display.pixel(x + 4, y, None, blink=True)
# first load the frame with the arrows; moves the an_arrow to the right in each
# frame
display.sleep(True) # turn display off while updating blink bits
display.fill(0)
for y in range(display.height):
row = an_arrow[y]
for x in range(8):
bit = 1 << (7-x) & row
if bit:
display.pixel(x + 4, y, 50, blink=True)

display.blink(300) # ranges from 270 to 2159; smaller the number to faster blink
display.sleep(False) # turn display on
display.blink(1000) # ranges from 270 to 2159; smaller the number to faster blink
display.sleep(False) # turn display on
50 changes: 27 additions & 23 deletions examples/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,35 @@
import busio
import adafruit_is31fl3731

i2c = busio.I2C(board.SCL, board.SDA)

# arrow pattern in bits; top row-> bottom row, 8 bits in each row
arrow = bytearray((0x08, 0x0c, 0xfe, 0xff, 0xfe, 0x0c, 0x08, 0x00, 0x00))

with busio.I2C(board.SCL, board.SDA) as i2c:
# initial display using Feather CharlieWing LED 15 x 7
display = adafruit_is31fl3731.CharlieWing(i2c)
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.Matrix(i2c)
# initial display using Feather CharlieWing LED 15 x 7
display = adafruit_is31fl3731.CharlieWing(i2c)
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.Matrix(i2c)
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.CharlieBonnet(i2c)


# first load the frame with the arrows; moves the arrow to the right in each
# frame
display.sleep(True) # turn display off while frames are updated
# first load the frame with the arrows; moves the arrow to the right in each
# frame
display.sleep(True) # turn display off while frames are updated
for frame in range(8):
display.frame(frame, show=False)
display.fill(0)
for y in range(display.height):
row = arrow[y]
for x in range(8):
bit = 1 << (7-x) & row
# display the pixel into selected frame with varying intensity
if bit:
display.pixel(x + frame, y, frame**2 + 1)
display.sleep(False)
# now tell the display to show the frame one at time
while True:
for frame in range(8):
display.frame(frame, show=False)
display.fill(0)
for y in range(display.height):
row = arrow[y]
for x in range(8):
bit = 1 << (7-x) & row
# display the pixel into selected frame with varying intensity
if bit:
display.pixel(x + frame, y, frame**2 + 1)
display.sleep(False)
# now tell the display to show the frame one at time
while True:
for frame in range(8):
display.frame(frame)
time.sleep(.1)
display.frame(frame)
time.sleep(.1)
32 changes: 18 additions & 14 deletions examples/is31fl3731_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@
import busio
import adafruit_is31fl3731

i2c = busio.I2C(board.SCL, board.SDA)

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

# draw a box on the display
# first draw the top and bottom edges
for x in range(display.width):
display.pixel(x, 0, 50)
display.pixel(x, display.height - 1, 50)
# now draw the left and right edges
for y in range(display.height):
display.pixel(0, y, 50)
display.pixel(display.width - 1, y, 50)
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.Matrix(i2c)

# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
#display = adafruit_is31fl3731.CharlieBonnet(i2c)

# draw a box on the display
# first draw the top and bottom edges
for x in range(display.width):
display.pixel(x, 0, 50)
display.pixel(x, display.height - 1, 50)
# now draw the left and right edges
for y in range(display.height):
display.pixel(0, y, 50)
display.pixel(display.width - 1, y, 50)
77 changes: 42 additions & 35 deletions examples/text.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,46 @@
import board
import busio
import framebuf
import adafruit_framebuf
import adafruit_is31fl3731

buf = bytearray(32)

with busio.I2C(board.SCL, board.SDA) as i2c:
# initial display using Feather CharlieWing LED 15 x 7
display = adafruit_is31fl3731.CharlieWing(i2c)
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.Matrix(i2c)

fb = framebuf.FrameBuffer(buf, display.width, display.height, framebuf.MONO_VLSB)
text_to_show = "Adafruit!!"
frame = 0 # start with frame 0
while True:
for i in range(len(text_to_show) * 9):
fb.fill(0)
fb.text(text_to_show, -i + display.width, 0)

# to improve the display flicker we can use two frame
# fill the next frame with scrolling text, then
# show it.
display.frame(frame, show=False)
# turn all LEDs off
display.fill(0)
for x in range(display.width):
# using the FrameBuffer text result
bite = buf[x]
for y in range(display.height):
bit = 1 << y & bite
# if bit > 0 then set the pixel brightness
if bit:
display.pixel(x, y, 50)

# now that the frame is filled, show it.
display.frame(frame, show=True)
frame = 0 if frame else 1

i2c = busio.I2C(board.SCL, board.SDA)

# initial display using Feather CharlieWing LED 15 x 7
#display = adafruit_is31fl3731.CharlieWing(i2c)
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.Matrix(i2c)
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
display = adafruit_is31fl3731.CharlieBonnet(i2c)

text_to_show = "Adafruit!!"

# Create a framebuffer for our display
buf = bytearray(32) # 2 bytes tall x 16 wide = 32 bytes (9 bits is 2 bytes)
fb = adafruit_framebuf.FrameBuffer(buf, display.width, display.height, adafruit_framebuf.MVLSB)


frame = 0 # start with frame 0
while True:
for i in range(len(text_to_show) * 9):
fb.fill(0)
fb.text(text_to_show, -i + display.width, 0, color=1)

# to improve the display flicker we can use two frame
# fill the next frame with scrolling text, then
# show it.
display.frame(frame, show=False)
# turn all LEDs off
display.fill(0)
for x in range(display.width):
# using the FrameBuffer text result
bite = buf[x]
for y in range(display.height):
bit = 1 << y & bite
# if bit > 0 then set the pixel brightness
if bit:
display.pixel(x, y, 50)

# now that the frame is filled, show it.
display.frame(frame, show=True)
frame = 0 if frame else 1
40 changes: 23 additions & 17 deletions examples/wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@
import busio
import adafruit_is31fl3731

i2c = busio.I2C(board.SCL, board.SDA)

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]

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

while True:
for incr in range(24):
# to reduce update flicker, use two frames
# make a frame active, don't show it yet
display.frame(frame, show=False)
# fill the display with the next frame
for x in range(display.width):
for y in range(display.height):
display.pixel(x, y, sweep[(x+y+incr)%24])
# show the next frame
display.frame(frame, show=True)
frame = 0 if frame else 1
# initialize display using Feather CharlieWing LED 15 x 7
display = adafruit_is31fl3731.CharlieWing(i2c)
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
#display = adafruit_is31fl3731.Matrix(i2c)
# uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet
#display = adafruit_is31fl3731.CharlieBonnet(i2c)

while True:
for incr in range(24):
# to reduce update flicker, use two frames
# make a frame active, don't show it yet
display.frame(frame, show=False)
# fill the display with the next frame
for x in range(display.width):
for y in range(display.height):
display.pixel(x, y, sweep[(x+y+incr)%24])
# show the next frame
display.frame(frame, show=True)
if frame:
frame = 0
else:
frame = 1
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Adafruit-Blinka
Adafruit-Blinka
adafruit-circuitpython-framebuf

0 comments on commit a76511f

Please sign in to comment.