Skip to content

Commit 8af2cf6

Browse files
authored
Merge pull request #19 from makermelissa/master
Added scrolling marquee example
2 parents 03acb80 + 14a94d1 commit 8af2cf6

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

examples/is31fl3731_pillow_marquee.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""
2+
Example to scroll some text as a marquee
3+
4+
This example is for use on (Linux) computers that are using CPython with
5+
Adafruit Blinka to support CircuitPython libraries. CircuitPython does
6+
not support PIL/pillow (python imaging library)!
7+
8+
Author(s): Melissa LeBlanc-Williams for Adafruit Industries
9+
"""
10+
11+
import board
12+
from PIL import Image, ImageDraw, ImageFont
13+
import adafruit_is31fl3731
14+
15+
SCROLLING_TEXT = "You can display a personal message here..."
16+
BRIGHTNESS = 64 # Brightness can be between 0-255
17+
18+
i2c = board.I2C()
19+
20+
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
21+
#display = adafruit_is31fl3731.Matrix(i2c)
22+
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
23+
display = adafruit_is31fl3731.CharlieBonnet(i2c)
24+
25+
# Load a font
26+
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 8)
27+
28+
# Create an image that contains the text
29+
text_width, text_height = font.getsize(SCROLLING_TEXT)
30+
text_image = Image.new('L', (text_width, text_height))
31+
text_draw = ImageDraw.Draw(text_image)
32+
text_draw.text((0, 0), SCROLLING_TEXT, font=font, fill=BRIGHTNESS)
33+
34+
# Create an image for the display
35+
image = Image.new('L', (display.width, display.height))
36+
draw = ImageDraw.Draw(image)
37+
38+
# Load the text in each frame
39+
while True:
40+
for x in range(text_width + display.width):
41+
draw.rectangle((0, 0, display.width, display.height), outline=0, fill=0)
42+
image.paste(text_image, (display.width - x, display.height // 2 - text_height // 2 - 1))
43+
display.image(image)

examples/is31fl3731_pillow_numbers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from PIL import Image, ImageDraw, ImageFont
1414
import adafruit_is31fl3731
1515

16+
BRIGHTNESS = 32 # Brightness can be between 0-255
17+
1618
i2c = board.I2C()
1719

1820
# uncomment line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix
@@ -32,7 +34,7 @@
3234
# Load the text in each frame
3335
for x in range(8):
3436
draw.rectangle((0, 0, display.width, display.height), outline=0, fill=0)
35-
draw.text((x + 1, -2), str(x + 1), font=font, fill=32)
37+
draw.text((x + 1, -2), str(x + 1), font=font, fill=BRIGHTNESS)
3638
display.image(image, frame=x)
3739

3840
display.autoplay(delay=500)

0 commit comments

Comments
 (0)