Skip to content

Commit

Permalink
Merge pull request #17 from makermelissa/master
Browse files Browse the repository at this point in the history
Added image function and font-based numbers example
  • Loading branch information
makermelissa committed Dec 5, 2019
2 parents 735b424 + 51e3aa2 commit 4d989cd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
24 changes: 23 additions & 1 deletion adafruit_is31fl3731.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
CircuitPython driver for the IS31FL3731 charlieplex IC.
* Author(s): Tony DiCola
* Author(s): Tony DiCola, Melissa LeBlanc-Williams
Implementation Notes
--------------------
Expand Down Expand Up @@ -335,6 +335,28 @@ def pixel(self, x, y, color=None, blink=None, frame=None):
return None
#pylint: enable-msg=too-many-arguments

def image(self, img, blink=None, frame=None):
"""Set buffer to value of Python Imaging Library image. The image should
be in 8-bit mode (L) and a size equal to the display size.
:param img: Python Imaging Library image
:param blink: True to blink
:param frame: the frame to set the image
"""
if img.mode != 'L':
raise ValueError('Image must be in mode L.')
imwidth, imheight = img.size
if imwidth != self.width or imheight != self.height:
raise ValueError('Image must be same dimensions as display ({0}x{1}).' \
.format(self.width, self.height))
# Grab all the pixels from the image, faster than getpixel.
pixels = img.load()

# Iterate through the pixels
for x in range(self.width): # yes this double loop is slow,
for y in range(self.height): # but these displays are small!
self.pixel(x, y, pixels[(x, y)], blink=blink, frame=frame)


class CharlieWing(Matrix):
"""Supports the Charlieplexed feather wing
Expand Down
34 changes: 34 additions & 0 deletions examples/is31fl3731_pillow_numbers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Example to utilize the Python Imaging Library (Pillow) and draw bitmapped text
to 8 frames and then run autoplay on those frames.
Author(s): Melissa LeBlanc-Williams for Adafruit Industries
"""

import board
from PIL import Image, ImageDraw, ImageFont
import adafruit_is31fl3731

i2c = board.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)

display.fill(0)

# 256 Color Grayscale Mode
image = Image.new('L', (display.width, display.height))
draw = ImageDraw.Draw(image)

# Load a font in 2 different sizes.
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 10)

# Load the text in each frame
for x in range(8):
draw.rectangle((0, 0, display.width, display.height), outline=0, fill=0)
draw.text((x + 1, -2), str(x + 1), font=font, fill=32)
display.image(image, frame=x)

display.autoplay(delay=500)

0 comments on commit 4d989cd

Please sign in to comment.