From 604f55da49b1d6e7c37996622db4da977bcfa9de Mon Sep 17 00:00:00 2001 From: ladyada Date: Wed, 20 Feb 2019 16:11:57 -0500 Subject: [PATCH 1/9] add charliebonnet & make I2C sharable --- adafruit_is31fl3731.py | 18 +++++++++++++++++ examples/is31fl3731_simpletest.py | 33 ++++++++++++++++++------------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index fe978e3..4a2b050 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -353,3 +353,21 @@ 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) + else: + return (x+1) * 16 + (7 - y) + + + diff --git a/examples/is31fl3731_simpletest.py b/examples/is31fl3731_simpletest.py index cc0a5a4..1ecfcee 100644 --- a/examples/is31fl3731_simpletest.py +++ b/examples/is31fl3731_simpletest.py @@ -2,19 +2,24 @@ 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) + +# 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) - # 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) From 61d3172ea0c84ee40296fbe40a256a5825aeb77e Mon Sep 17 00:00:00 2001 From: ladyada Date: Wed, 20 Feb 2019 16:16:07 -0500 Subject: [PATCH 2/9] remove trinary, make i2c sharable --- examples/wave.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/examples/wave.py b/examples/wave.py index f3e48dc..21523d8 100644 --- a/examples/wave.py +++ b/examples/wave.py @@ -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 From 7190c1489da645cc84c34a82cef1586b70d63bce Mon Sep 17 00:00:00 2001 From: ladyada Date: Wed, 20 Feb 2019 16:17:21 -0500 Subject: [PATCH 3/9] remvoe whitespace --- adafruit_is31fl3731.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index 4a2b050..0fa9303 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -356,8 +356,7 @@ def pixel_addr(x, y): class CharlieBonnet(Matrix): - """Supports the Charlieplexed bonnet - """ + """Supports the Charlieplexed bonnet""" width = 16 height = 8 @@ -368,6 +367,3 @@ def pixel_addr(x, y): return (x-6) * 16 - (y + 1) else: return (x+1) * 16 + (7 - y) - - - From 4caf5eaac4c676c6d9e7198f94f6167893d137d9 Mon Sep 17 00:00:00 2001 From: ladyada Date: Wed, 20 Feb 2019 16:20:59 -0500 Subject: [PATCH 4/9] linting --- adafruit_is31fl3731.py | 3 +-- examples/is31fl3731_simpletest.py | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/adafruit_is31fl3731.py b/adafruit_is31fl3731.py index 0fa9303..35122fb 100644 --- a/adafruit_is31fl3731.py +++ b/adafruit_is31fl3731.py @@ -365,5 +365,4 @@ 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) - else: - return (x+1) * 16 + (7 - y) + return (x+1) * 16 + (7 - y) diff --git a/examples/is31fl3731_simpletest.py b/examples/is31fl3731_simpletest.py index 1ecfcee..eae4851 100644 --- a/examples/is31fl3731_simpletest.py +++ b/examples/is31fl3731_simpletest.py @@ -22,4 +22,3 @@ for y in range(display.height): display.pixel(0, y, 50) display.pixel(display.width - 1, y, 50) - From f6eb26378610cce0f9e64cdf1a84c08352bdc52e Mon Sep 17 00:00:00 2001 From: ladyada Date: Wed, 20 Feb 2019 18:10:55 -0500 Subject: [PATCH 5/9] no context i2c, make less bright, slower blink --- examples/blink.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/examples/blink.py b/examples/blink.py index 97cfd66..8910142 100644 --- a/examples/blink.py +++ b/examples/blink.py @@ -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 From 4fdc2b72a54176e2964c2c6563ce4badf6b0a223 Mon Sep 17 00:00:00 2001 From: ladyada Date: Wed, 20 Feb 2019 18:17:42 -0500 Subject: [PATCH 6/9] update frame demo to no context i2c, add bonnet --- examples/frame.py | 50 +++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/examples/frame.py b/examples/frame.py index e21d23e..6ff22f0 100644 --- a/examples/frame.py +++ b/examples/frame.py @@ -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) From 4babcac2673a5a335eb7b6940d524051ea5e8c5c Mon Sep 17 00:00:00 2001 From: ladyada Date: Wed, 20 Feb 2019 18:25:22 -0500 Subject: [PATCH 7/9] fix for adafruit_framebuf --- examples/text.py | 77 ++++++++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/examples/text.py b/examples/text.py index cb3ad9f..3f7d27d 100644 --- a/examples/text.py +++ b/examples/text.py @@ -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 From 5746a5719ff3a669b4a84d842b7ee2135075d07e Mon Sep 17 00:00:00 2001 From: ladyada Date: Fri, 22 Feb 2019 10:10:11 -0500 Subject: [PATCH 8/9] new requirement, soft framebuf --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6b4e64a..2b802ba 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -Adafruit-Blinka \ No newline at end of file +Adafruit-Blinka +adafruit-circuitpython-framebuf \ No newline at end of file From 3caf17ca81c2f2bc5de4d197e4e7a1ab1ec36a43 Mon Sep 17 00:00:00 2001 From: ladyada Date: Fri, 22 Feb 2019 10:13:26 -0500 Subject: [PATCH 9/9] lint --- examples/text.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/text.py b/examples/text.py index 3f7d27d..2ad8741 100644 --- a/examples/text.py +++ b/examples/text.py @@ -25,7 +25,7 @@ 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.