|
| 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) |
0 commit comments