Adafruit ESP32-S3 Manual page 184

Tft feather
Table of Contents

Advertisement

async def rainbow_cycle(controls):
"""Rainbow cycle animation on ring one."""
while True:
for j in range(255, -1, -1) if controls.reverse else range(0, 256, 1):
for i in range(num_pixels):
rc_index = (i * 256 // num_pixels) + j
ring_one[i] = colorwheel(rc_index & 255)
ring_one.show()
await asyncio.sleep(controls.wait)
async def blink(controls):
"""Blink animation on ring two."""
while True:
ring_two.fill((0, 0, 255))
ring_two.show()
await asyncio.sleep(controls.delay)
ring_two.fill((0, 0, 0))
ring_two.show()
await asyncio.sleep(controls.delay)
await asyncio.sleep(controls.wait)
async def monitor_button(button, controls):
"""Monitor button that reverses rainbow direction and changes blink speed.
Assume button is active low.
"""
with keypad.Keys((button,), value_when_pressed=False, pull=True) as key:
while True:
key_event = key.events.get()
if key_event:
if key_event.pressed:
elif key_event.released:
await asyncio.sleep(0)
async def main():
animation_controls = AnimationControls()
button_task = asyncio.create_task(monitor_button(button_pin,
animation_controls))
animation_task = asyncio.create_task(rainbow_cycle(animation_controls))
blink_task = asyncio.create_task(blink(animation_controls))
# This will run forever, because no tasks ever finish.
await asyncio.gather(button_task, animation_task, blink_task)
asyncio.run(main())
Your CIRCUITPY drive contents should resemble the image below.
You should have at least the following file in the top level of the CIRCUITPY drive:
code.py
Your CIRCUITPY/lib folder should contain at least the following folder and files:
asyncio/
©Adafruit Industries
controls.reverse = True
controls.delay = 0.1
controls.reverse = False
controls.delay = 0.5
Page 184 of 263

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32-S3 and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents

Save PDF