Adafruit ESP32-S3 Manual page 186

Tft feather
Table of Contents

Advertisement

Then, you specify the button pin, the number of LEDs in each NeoPixel ring, and the
LED brightness.
button_pin = board.BUTTON
num_pixels = 16
brightness = 0.2
Next you set up the two NeoPixel rings on pins
pixels and brightness specified above, and setting
ring_one = neopixel.NeoPixel(board.A1, num_pixels, brightness=brightness,
auto_write=False)
ring_two = neopixel.NeoPixel(board.A2, num_pixels, brightness=brightness,
auto_write=False)
Following set up, you create a class called
ways to control the animations with asyncio.
class AnimationControls:
def __init__(self):
self.reverse = False
self.wait = 0.0
self.delay = 0.5
Then, you have the rainbow and blink animation code. This is where the asyncio-
specific code begins.
In terms of the animation parts of the code, the first function is the rainbow cycle
animation code. This is pretty standard except for the second line of code. In this
example, the line beginning with
rainbow cycle in reverse:
by the standard forward rainbow cycle code -
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)
The second function is the blink animation code. This is typical. You fill all the
NeoPixel LEDs blue, delay for a specified amount of time, then turn all of the LEDs off,
and delay for the same specified amount of time.
©Adafruit Industries
AnimationControls
includes non-standard code for the
for j in
range(255, -1, -1) if controls.reverse
and
, using the number of
A1
A2
auto_write=False
. This class provides
range(0, 256, 1)
.
, followed
.
Page 186 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?

Table of Contents

Save PDF