import board from PIL import Image, ImageDraw, ImageFont # uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix # from adafruit_is31fl3731.matrix import Matrix as Display # uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display # uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 # from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display BRIGHTNESS = 32 # Brightness can be between 0-255 i2c = board.I2C() display = Display(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=BRIGHTNESS)
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix # from adafruit_is31fl3731.matrix import Matrix as Display # uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display # uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 # from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display # uncomment next line if you are using Pimoroni 11x7 LED Matrix Breakout # from adafruit_is31fl3731.matrix_11x7 import Matrix11x7 as Display # uncomment this line if you use a Pico, here with SCL=GP21 and SDA=GP20. # i2c = busio.I2C(board.GP21, board.GP20) i2c = busio.I2C(board.SCL, board.SDA) display = Display(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
# uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix # from adafruit_is31fl3731.matrix import Matrix as Display # uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display # uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 # from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display # uncomment next line if you are using Pimoroni 11x7 LED Matrix Breakout # from adafruit_is31fl3731.matrix_11x7 import Matrix11x7 as Display # uncomment this line if you use a Pico, here with SCL=GP21 and SDA=GP20. # i2c = busio.I2C(board.GP21, board.GP20) i2c = busio.I2C(board.SCL, board.SDA) display = Display(i2c) display.fill(0) # draw a box on the display # first draw the top and bottom edges for x in range(display.width): print('X is: {}'.format(x)) 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): print('Y is: {}'.format(y)) display.pixel(0, y, 50) display.pixel(display.width - 1, y, 50) # for y in range(display.height):
import sys import board from PIL import Image # uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix # from adafruit_is31fl3731.matrix import Matrix as Display # uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display # uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 # from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display i2c = board.I2C() display = Display(i2c) # Open the gif if len(sys.argv) < 2: print("No image file specified") print("Usage: python3 is31fl3731_pillow_animated_gif.py animated.gif") sys.exit() image = Image.open(sys.argv[1]) # Make sure it's animated if not image.is_animated: print("Specified image is not animated") sys.exit() # Get the autoplay information from the gif
from PIL import Image, ImageDraw, ImageFont # uncomment next line if you are using Adafruit 16x9 Charlieplexed PWM LED Matrix # from adafruit_is31fl3731.matrix import Matrix as Display # uncomment next line if you are using Adafruit 16x8 Charlieplexed Bonnet from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display # uncomment next line if you are using Pimoroni Scroll Phat HD LED 17 x 7 # from adafruit_is31fl3731.scroll_phat_hd import ScrollPhatHD as Display SCROLLING_TEXT = "You can display a personal message here..." BRIGHTNESS = 64 # Brightness can be between 0-255 i2c = board.I2C() display = Display(i2c) # Load a font font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 8) # Create an image that contains the text text_width, text_height = font.getsize(SCROLLING_TEXT) text_image = Image.new("L", (text_width, text_height)) text_draw = ImageDraw.Draw(text_image) text_draw.text((0, 0), SCROLLING_TEXT, font=font, fill=BRIGHTNESS) # Create an image for the display image = Image.new("L", (display.width, display.height)) draw = ImageDraw.Draw(image) # Load the text in each frame
import time from math import atan2, degrees import board import busio import adafruit_mpu6050 from adafruit_is31fl3731.charlie_bonnet import CharlieBonnet as Display gyroi2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_mpu6050.MPU6050(gyroi2c) ledi2c = busio.I2C(board.SCL, board.SDA) display = Display(ledi2c) display.fill(0) # Given a point (x, y) return the angle of that point relative to x axis. # Returns: angle in degrees def vector_2_degrees(x, y): angle = degrees(atan2(y, x)) if angle < 0: angle += 360 return angle # Given an accelerometer sensor object return the inclination angles of X/Z and Y/Z # Returns: tuple containing the two angles in degrees