Here are a few code samples to get you started.

Plug your computer into the QY Py via a known, good power+data USB cable. A new thumb drive named CIRCUITPY should appear.

Download the file and save it as code.py at the root of your CIRCUITPY drive to install.

All On

This code will turn all of the noods on.

# Adafruit nOOds digital control using GPIO pins.
# Uses 3 nOOds, anode (+) to GPIO pin, cathode (-) to ground.
# A current-limiting resistor (e.g. 220 Ohm) can go at either end.

import time
import board
import digitalio

# This uses 3 pins on QtPy RP2040, but any pins will do.
PINS = (board.A3, board.SDA, board.SCL) # List of pins, one per nOOd

# Convert pin number list to pin object list, initialize to OFF
pin_list = [digitalio.DigitalInOut(pin) for pin in PINS]
for pin in pin_list:
    pin.direction = digitalio.Direction.OUTPUT
    pin.value = 0

while True:              # Repeat forever...
    for pin in pin_list: # For each pin...
        pin.value = True # nOOd on

Blink in Sequence

This code blinks each nood in sequence.

# Adafruit nOOds digital control using GPIO pins.
# Uses 3 nOOds, anode (+) to GPIO pin, cathode (-) to ground.
# A current-limiting resistor (e.g. 220 Ohm) can go at either end.

import time
import board
import digitalio

# This uses 3 pins on QtPy RP2040, but any pins will do.
PINS = (board.A3, board.SDA, board.SCL) # List of pins, one per nOOd

# Convert pin number list to pin object list, initialize to OFF
pin_list = [digitalio.DigitalInOut(pin) for pin in PINS]
for pin in pin_list:
    pin.direction = digitalio.Direction.OUTPUT
    pin.value = False

while True:               # Repeat forever...
    for pin in pin_list:  # For each pin...
        pin.value = True  # nOOd on
        time.sleep(0.5)   # Pause 1/2 sec
        pin.value = False # nOOd off

Fade in Sequence

This code provides a fade effect, sequencing each nood.

# Adafruit nOOds "analog" (PWM) brightness control using GPIO.
# Uses 3 nOOds, anode (+) to GPIO pin, cathode (-) to ground.
# A current-limiting resistor (e.g. 220 Ohm) can go at either end.

import math
import time
import board
import pwmio

# This uses 3 pins on QtPy RP2040, but any pins will do.
PINS = (board.A3, board.SDA, board.SCL) # List of pins, one per nOOd
GAMMA = 2.6  # For perceptually-linear brightness

# Convert pin number list to PWMOut object list
pin_list = [pwmio.PWMOut(pin, frequency=1000, duty_cycle=0) for pin in PINS]

while True:                            # Repeat forever...
    for i, pin in enumerate(pin_list): # For each pin...
        # Calc sine wave, phase offset for each pin, with gamma correction.
        # If using red, green, blue nOOds, you'll get a cycle of hues.
        phase = (time.monotonic() - 2 * i / len(PINS)) * math.pi
        brightness = int((math.sin(phase) + 1.0) * 0.5 ** GAMMA * 65535 + 0.5)
        pin.duty_cycle = brightness

This guide was first published on Jan 11, 2023. It was last updated on Jul 08, 2024.

This page (Example Code) was last updated on Mar 08, 2024.

Text editor powered by tinymce.