Skip to content

Commit 6cc2244

Browse files
authored
Merge pull request #2658 from adafruit/led_noodle_tree
Adding code for LED Noodle Tree learn guide
2 parents 5352e15 + 86532fa commit 6cc2244

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

LED_Noodle_Tree/code.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# SPDX-FileCopyrightText: 2023 Phil Burgess for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import math
6+
import time
7+
import board
8+
import adafruit_aw9523
9+
10+
GAMMA = 2.6 # For perceptually-linear brightness
11+
PINS = (15, 14, 13, 12, 7, 6, 5, 4) # List of pins, one per nOOd
12+
13+
# Instantiate AW9523 on STEMMA I2C bus. This was tested on QT Py RP2040.
14+
# Other boards might require board.I2C() instead of board.STEMMA_I2C().
15+
aw = adafruit_aw9523.AW9523(board.STEMMA_I2C())
16+
17+
for pin in PINS:
18+
aw.get_pin(pin).switch_to_output(value=True) # Activate pin, initialize OFF
19+
aw.LED_modes |= 1 << pin # Enable constant-current on pin
20+
21+
while True: # Repeat forever...
22+
for i, pin in enumerate(PINS): # For each pin...
23+
# Calc sine wave, phase offset for each pin, with gamma correction.
24+
# If using red, green, blue nOOds, you'll get a cycle of hues.
25+
phase = (time.monotonic() - 2 * i / len(PINS)) * math.pi
26+
brightness = int((math.sin(phase) + 1.0) * 0.5 ** GAMMA * 255 + 0.5)
27+
aw.set_constant_current(pin, brightness)

0 commit comments

Comments
 (0)