Breadboard
docs
Example project · Displays

Ring with a power switch

The toggle switch gates the NeoPixel ring's 5 V pin while the ESP32-C3 keeps streaming rainbow frames: flick it off and the ring goes dark instantly; flick it on and the next frame repaints.

The Ring with a power switch circuit as rendered by the simulator

What's on the bench

  • Battery
  • ESP32-C3
  • NeoPixel ring ×12
  • Toggle switch

How it's wired

  • hole a10hole B-5
  • hole a11hole B+5
  • hole B+9hole a30
  • hole c32hole a40
  • hole a42hole B-9
  • hole a14hole c41

The code

This MicroPython script runs on the emulated board every boot; edit it in the Code tab.

# Rainbow chase on the ring. The toggle switch gates the ring's 5 V pin:
# flick it off and the pixels go dark instantly; flick it back on and the
# next frame repaints them. The C3 keeps streaming frames throughout.
import machine, neopixel, time

RAINBOW = [
    (255, 0, 0), (255, 96, 0), (255, 200, 0), (96, 255, 0),
    (0, 255, 60), (0, 255, 200), (0, 160, 255), (0, 40, 255),
    (90, 0, 255), (200, 0, 255), (255, 0, 160), (255, 0, 60),
]
np = neopixel.NeoPixel(machine.Pin(2), 12)
for step in range(4000):
    for i in range(12):
        np[i] = RAINBOW[(i + step) % 12]
    np.write()
    time.sleep_ms(120)
print('ring demo done')

Related projects