Skip to content

Instantly share code, notes, and snippets.

@lizzybrooks
Last active February 9, 2026 23:56
Show Gist options
  • Select an option

  • Save lizzybrooks/93e49a8de6800ade80df5a00552eec98 to your computer and use it in GitHub Desktop.

Select an option

Save lizzybrooks/93e49a8de6800ade80df5a00552eec98 to your computer and use it in GitHub Desktop.
import time
import board
import neopixel
from digitalio import DigitalInOut, Direction, Pull
switch = DigitalInOut(board.D3)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
pixel_pin = board.D2
num_pixels = 16
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.7, auto_write=False)
on = 0
RED = (255, 0, 0)
YELLOW = (255, 150, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
PURPLE = (180, 0, 255)
WHITE = (255, 255, 255)
OFF = (0, 0, 0)
while True:
if (switch.value == 0 and on == 0):
print(on)
pixels[1] = YELLOW
pixels[2] = BLUE
pixels[3] = GREEN
pixels[4] = CYAN
pixels[5] = YELLOW
pixels[6] = BLUE
pixels[7] = GREEN
pixels[8] = CYAN
pixels[9] = YELLOW
pixels[10] = BLUE
pixels[11] = GREEN
pixels[12] = CYAN
pixels[13] = YELLOW
pixels[14] = BLUE
pixels[15] = GREEN
pixels[0] = CYAN
pixels.show()
on = 1
if (switch.value == 1 and on == 1):
print(on)
for i in range(0, 16, 1):
pixels[i] = OFF
pixels.show()
on = 0 # ← Now properly indented inside the if block
time.sleep(0.2)
print(on)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment