/ EyeLights_BMP_Animation / code.py
code.py
1 # SPDX-FileCopyrightText: 2021 Phil Burgess for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 """ 6 EyeLightsAnim example for Adafruit EyeLights (LED Glasses + Driver). 7 The accompanying eyelights_anim.py provides pre-drawn frame-by-frame 8 animation from BMP images. Sort of a catch-all for modest projects that may 9 want to implement some animation without having to express that animation 10 entirely in code. The idea is based upon two prior projects: 11 12 https://learn.adafruit.com/32x32-square-pixel-display/overview 13 learn.adafruit.com/circuit-playground-neoanim-using-bitmaps-to-animate-neopixels 14 15 The 18x5 matrix and the LED rings are regarded as distinct things, fed from 16 two separate BMPs (or can use just one or the other). The former guide above 17 uses the vertical axis for time (like a strip of movie film), while the 18 latter uses the horizontal axis for time (as in audio or video editing). 19 Despite this contrast, the same conventions are maintained here to avoid 20 conflicting explanations...what worked in those guides is what works here, 21 only the resolutions are different. See also the example BMPs. 22 """ 23 24 import time 25 import board 26 from busio import I2C 27 import adafruit_is31fl3741 28 from adafruit_is31fl3741.adafruit_ledglasses import LED_Glasses 29 from eyelights_anim import EyeLightsAnim 30 31 32 # HARDWARE SETUP ----------------------- 33 34 i2c = I2C(board.SCL, board.SDA, frequency=1000000) 35 36 # Initialize the IS31 LED driver, buffered for smoother animation 37 glasses = LED_Glasses(i2c, allocate=adafruit_is31fl3741.MUST_BUFFER) 38 glasses.show() # Clear any residue on startup 39 glasses.global_current = 20 # Just middlin' bright, please 40 41 42 # ANIMATION SETUP ---------------------- 43 44 # Two indexed-color BMP filenames are specified: first is for the LED matrix 45 # portion, second is for the LED rings -- or pass None for one or the other 46 # if not animating that part. The two elements, matrix and rings, share a 47 # few LEDs in common...by default the rings appear "on top" of the matrix, 48 # or you can optionally pass a third argument of False to have the rings 49 # underneath. There's that one odd unaligned pixel between the two though, 50 # so this may only rarely be desirable. 51 anim = EyeLightsAnim(glasses, "matrix.bmp", "rings.bmp") 52 53 54 # MAIN LOOP ---------------------------- 55 56 # This example just runs through a repeating cycle. If you need something 57 # else, like ping-pong animation, or frames based on a specific time, the 58 # anim.frame() function can optionally accept two arguments: an index for 59 # the matrix animation, and an index for the rings. 60 61 while True: 62 anim.frame() # Advance matrix and rings by 1 frame and wrap around 63 glasses.show() # Update LED matrix 64 time.sleep(0.02) # Pause briefly