This commit is contained in:
2026-06-16 13:02:06 +02:00
commit 9e45f1f199
29 changed files with 2531 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
import machine
import time
import neopixel
# NeoPixel setup
NUM_LEDS = 3
np = neopixel.NeoPixel(machine.Pin(17), NUM_LEDS)
# Buttons
button_pins = [20, 21, 22]
buttons = [machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP) for pin in button_pins]
# Colors to cycle through
colors = [
(255, 0, 0), # Red
(0, 255, 0), # Green
(0, 0, 255), # Blue
(255, 255, 0), # Yellow
(255, 0, 255), # Magenta
(0, 255, 255), # Cyan
(255, 255, 255) # White
]
# Individual color indexes for each pixel
indexes = [0, 0, 0]
last_state = [1, 1, 1] # buttons start unpressed
def show_pixels():
for i in range(NUM_LEDS):
np[i] = colors[indexes[i]]
np.write()
# Initial display
show_pixels()
while True:
for i in range(3):
state = buttons[i].value()
# Detect press (1 → 0)
if last_state[i] == 1 and state == 0:
indexes[i] = (indexes[i] + 1) % len(colors)
show_pixels()
time.sleep_ms(200) # debounce
last_state[i] = state
time.sleep_ms(10)

10
Maker_Pico_Box/button.py Normal file
View File

@@ -0,0 +1,10 @@
import machine
import time
while True:
if machine.bootsel_button():
print("BOOTSEL button pressed!")
else:
print("Not pressed.")
time.sleep(0.2)

View File

@@ -0,0 +1,44 @@
import machine
import neopixel
import time
# NeoPixel setup
NUM_LEDS = 8
np = neopixel.NeoPixel(machine.Pin(28), NUM_LEDS)
# Button on GP22 (active LOW)
button = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_UP)
# Color list (R, G, B)
colors = [
(255, 0, 0), # Red
(0, 255, 0), # Green
(0, 0, 255), # Blue
(255, 255, 0), # Yellow
(255, 0, 255), # Magenta
(0, 255, 255), # Cyan
(255, 255, 255) # White
]
current_color = 0
last_state = 1 # button not pressed
def show_color(color):
for i in range(NUM_LEDS):
np[i] = color
np.write()
# Initial color
show_color(colors[current_color])
while True:
state = button.value()
# Detect button press (HIGH → LOW)
if last_state == 1 and state == 0:
current_color = (current_color + 1) % len(colors)
show_color(colors[current_color])
time.sleep_ms(200) # Debounce delay
last_state = state
time.sleep_ms(10)

View File

@@ -0,0 +1,32 @@
import machine
import neopixel
import time
# NeoPixel setup
NUM_LEDS = 8
np = neopixel.NeoPixel(machine.Pin(28), NUM_LEDS)
# Button on GP22 (active LOW)
button = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_UP)
# Color list (R, G, B)
colors = [
(0, 0, 0),
(255, 0, 0), # Red
(0, 255, 0), # Green
(0, 0, 255), # Blue
(255, 255, 0), # Yellow
(255, 0, 255), # Magenta
(0, 255, 255), # Cyan
(255, 255, 255) # White
]
current_color = 0
last_state = 1 # button not pressed
def show_color(color):
for i in range(NUM_LEDS):
np[i] = color
np.write()
show_color(colors[current_color])

172
Maker_Pico_Box/main.py Normal file
View File

@@ -0,0 +1,172 @@
import machine
import time
import neopixel
# ============================================================
# HEARTBEAT CLASS — smooth fade with MIN + MAX brightness
# ============================================================
class HeartbeatFadeNeoPixel:
def __init__(self, neopixel_obj, pixel_index=0, color=(255, 0, 0),
min_brightness=5, max_brightness=100,
step=2, interval_ms=20):
self.np = neopixel_obj
self.index = pixel_index
self.color = color
self.min_brightness = min_brightness
self.max_brightness = max_brightness
self.step = step
self.interval = interval_ms
self.brightness = min_brightness
self.direction = 1 # 1 = fade up, -1 = fade down
self.last_time = time.ticks_ms()
def apply_brightness(self, c, level):
r, g, b = c
factor = level / 100
return (int(r * factor), int(g * factor), int(b * factor))
def update(self):
now = time.ticks_ms()
if time.ticks_diff(now, self.last_time) >= self.interval:
self.last_time = now
# Update brightness
self.brightness += self.direction * self.step
# Bounce at limits
if self.brightness >= self.max_brightness:
self.brightness = self.max_brightness
self.direction = -1
if self.brightness <= self.min_brightness:
self.brightness = self.min_brightness
self.direction = 1
# Apply brightness
self.np[self.index] = self.apply_brightness(self.color, self.brightness)
self.np.write()
# ============================================================
# NEOPIXEL SETUP
# ============================================================
STRIP_PIN = 17
STRIP_LEDS = 3
strip = neopixel.NeoPixel(machine.Pin(STRIP_PIN), STRIP_LEDS)
SINGLE_PIN = 28
single = neopixel.NeoPixel(machine.Pin(SINGLE_PIN), 1)
# ============================================================
# BUTTONS
# ============================================================
button_pins = [20, 21, 22]
buttons = [machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP) for pin in button_pins]
# ============================================================
# COLOR PALETTE
# ============================================================
colors = [
(0, 0, 0), # Off
(255, 0, 0), # Red
(0, 255, 0), # Green
(0, 0, 255), # Blue
# (255, 255, 0), # Yellow
# (0, 255, 255), # Cyan
# (255, 0, 255), # Magenta
# (255, 128, 0), # Orange
# (128, 0, 255), # Purple
# (255, 20, 147), # Pink
# (128, 255, 0), # Lime
(255, 255, 255), # White
]
# ============================================================
# STRIP STATE
# ============================================================
color_index = [0, 0, 0]
brightness = [50, 50, 50]
last_state = [1, 1, 1]
press_time = [0, 0, 0]
# ============================================================
# HEARTBEAT CONFIG (NOW HAS MIN + MAX)
# ============================================================
FLASH_COLOR_INDEX = 1 # Palette color
FLASH_MIN = 1 # << lowest brightness (0100)
FLASH_MAX = 10 # << highest brightness
FLASH_STEP = 0.2 # fade speed
FLASH_INTERVAL_MS = 20 # smoothness
heartbeat = HeartbeatFadeNeoPixel(
neopixel_obj=single,
pixel_index=0,
color=colors[FLASH_COLOR_INDEX],
min_brightness=FLASH_MIN,
max_brightness=FLASH_MAX,
step=FLASH_STEP,
interval_ms=FLASH_INTERVAL_MS
)
# ============================================================
# HELPERS
# ============================================================
def apply_brightness(color, level):
r, g, b = color
factor = level / 100
return (int(r * factor), int(g * factor), int(b * factor))
def update_strip():
for i in range(STRIP_LEDS):
strip[i] = apply_brightness(colors[color_index[i]], brightness[i])
strip.write()
# ============================================================
# INITIAL
# ============================================================
update_strip()
# ============================================================
# MAIN LOOP
# ============================================================
while True:
now = time.ticks_ms()
# BUTTON CONTROLLED PIXELS (02)
for i in range(3):
state = buttons[i].value()
if last_state[i] == 1 and state == 0:
press_time[i] = now
if last_state[i] == 0 and state == 1:
duration = time.ticks_diff(now, press_time[i])
if duration > 500:
brightness[i] += 10
if brightness[i] > 100:
brightness[i] = 10
else:
color_index[i] = (color_index[i] + 1) % len(colors)
update_strip()
time.sleep_ms(200)
last_state[i] = state
# HEARTBEAT ON GP28
heartbeat.update()
time.sleep_ms(10)

111
Maker_Pico_Box/main3.py Normal file
View File

@@ -0,0 +1,111 @@
import machine
import time
import neopixel
# ----------------------------
# NeoPixel SETUP
# ----------------------------
# Strip on GP17 (3 LEDs)
STRIP_PIN = 17
STRIP_LEDS = 3
strip = neopixel.NeoPixel(machine.Pin(STRIP_PIN), STRIP_LEDS)
# Single Pixel on GP28 (1 LED)
SINGLE_PIN = 28
single = neopixel.NeoPixel(machine.Pin(SINGLE_PIN), 1)
# ----------------------------
# Buttons on GP20, GP21, GP22
# ----------------------------
button_pins = [20, 21, 22]
buttons = [machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP) for pin in button_pins]
# ----------------------------
# 12-color palette
# ----------------------------
colors = [
(0, 0, 0), # Off
(255, 0, 0), # Red
(0, 255, 0), # Green
(0, 0, 255), # Blue
(255, 255, 0), # Yellow
(0, 255, 255), # Cyan
(255, 0, 255), # Magenta
(255, 128, 0), # Orange
(128, 0, 255), # Purple
(255, 20, 147), # Pink
(128, 255, 0), # Lime
(255, 255, 255), # White
]
# State for strip pixels (02)
color_index = [0, 0, 0]
brightness = [5, 5, 5]
last_state = [1, 1, 1]
press_time = [0, 0, 0]
# State for single pixel (pixel #3)
single_color_index = 1
single_brightness = 5
# ----------------------------
# Helpers
# ----------------------------
def apply_brightness(color, level):
r, g, b = color
factor = level / 100
return (int(r * factor), int(g * factor), int(b * factor))
def update_strip():
for i in range(STRIP_LEDS):
strip[i] = apply_brightness(colors[color_index[i]], brightness[i])
strip.write()
def update_single():
single[0] = apply_brightness(colors[single_color_index], single_brightness)
single.write()
# Initial setup
update_strip()
update_single()
# ----------------------------
# Main loop
# ----------------------------
while True:
now = time.ticks_ms()
# Handle buttons for pixels 0,1,2
for i in range(3):
state = buttons[i].value()
# Button pressed
if last_state[i] == 1 and state == 0:
press_time[i] = now
# Button released
if last_state[i] == 0 and state == 1:
duration = time.ticks_diff(now, press_time[i])
if duration > 500:
# LONG PRESS → brightness
brightness[i] += 10
if brightness[i] > 100:
brightness[i] = 10
else:
# SHORT PRESS → color change
color_index[i] = (color_index[i] + 1) % len(colors)
update_strip()
time.sleep_ms(200) # debounce
last_state[i] = state
# (Optional) Example automatic color change for pixel 3
# single_color_index = (single_color_index + 1) % len(colors)
# update_single()
# time.sleep(0.5)
time.sleep_ms(10)

342
Maker_Pico_Box/main4.py Normal file
View File

@@ -0,0 +1,342 @@
import machine
import time
import neopixel
# ============================================================
# NEOPIXELS
# ============================================================
# 3-LED strip on GP17
STRIP_PIN = 17
STRIP_LEDS = 3
strip = neopixel.NeoPixel(machine.Pin(STRIP_PIN), STRIP_LEDS)
# Single flashing LED on GP28
SINGLE_PIN = 28
single = neopixel.NeoPixel(machine.Pin(SINGLE_PIN), 1)
# ============================================================
# BUTTONS (GP20, GP21, GP22)
# ============================================================
button_pins = [20, 21, 22]
buttons = [machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP) for pin in button_pins]
# ============================================================
# COLOR PALETTE (index-based)
# ============================================================
colors = [
(0, 0, 0), # 0 Off
(255, 0, 0), # 1 Red
(0, 255, 0), # 2 Green
(0, 0, 255), # 3 Blue
(255, 255, 0), # 4 Yellow
(0, 255, 255), # 5 Cyan
(255, 0, 255), # 6 Magenta
(255, 128, 0), # 7 Orange
(128, 0, 255), # 8 Purple
(255, 20, 147), # 9 Pink
(128, 255, 0), # 10 Lime
(255, 255, 255) # 11 White
]
# ============================================================
# STATE FOR PIXELS 0-2 (buttons)
# ============================================================
color_index = [0, 0, 0] # Color for each strip LED
brightness = [5, 5, 5] # Brightness 0100%
last_state = [1, 1, 1]
press_time = [0, 0, 0]
# ============================================================
# FLASHING SINGLE PIXEL (GP28)
# ============================================================
FLASH_COLOR_INDEX = 1 # Choose color from palette (010)
FLASH_BRIGHTNESS = 5 # 0100%
FLASH_INTERVAL_MS = 500 # Flash speed
flash_on = False
last_flash_time = time.ticks_ms()
# ============================================================
# HELPER FUNCTIONS
# ============================================================
def apply_brightness(color, level):
r, g, b = color
factor = level / 100
return (int(r * factor), int(g * factor), int(b * factor))
def update_strip():
for i in range(STRIP_LEDS):
strip[i] = apply_brightness(colors[color_index[i]], brightness[i])
strip.write()
def single_on():
c = apply_brightness(colors[FLASH_COLOR_INDEX], FLASH_BRIGHTNESS)
single[0] = c
single.write()
def single_off():
single[0] = (0, 0, 0)
single.write()
# ============================================================
# INITIAL STATE
# ============================================================
update_strip()
single_off()
class HeartbeatNeoPixel:
def __init__(self, neopixel_obj, pixel_index=0, color=(255, 0, 0), brightness=50, interval_ms=500):
self.np = neopixel_obj
self.index = pixel_index
self.color = color
self.brightness = brightness
self.interval = interval_ms
self.state = False
self.last_time = time.ticks_ms()
def apply_brightness(self, c):
r, g, b = c
factor = self.brightness / 100
return (int(r * factor), int(g * factor), int(b * factor))
def update(self):
now = time.ticks_ms()
if time.ticks_diff(now, self.last_time) >= self.interval:
self.state = not self.state
self.last_time = now
if self.state:
self.np[self.index] = self.apply_brightness(self.color)
else:
self.np[self.index] = (0, 0, 0)
self.np.write()
# heartbeat = HeartbeatNeoPixel(
# neopixel_obj=single,
# pixel_index=0,
# color=colors[FLASH_COLOR_INDEX],
# brightness=FLASH_BRIGHTNESS,
# interval_ms=FLASH_INTERVAL_MS
# )
# ============================================================
# MAIN LOOP
# ============================================================
while True:
now = time.ticks_ms()
# -----------------------------
# BUTTONS → control pixels 02
# -----------------------------
heartbeat.update()
for i in range(3):
state = buttons[i].value()
if last_state[i] == 1 and state == 0:
press_time[i] = now
if last_state[i] == 0 and state == 1:
duration = time.ticks_diff(now, press_time[i])
if duration > 500:
# LONG PRESS → adjust brightness
brightness[i] += 10
if brightness[i] > 100:
brightness[i] = 10
else:
# SHORT PRESS → next color
color_indimport machine
import time
import neopixel
# ============================================================
# HEARTBEAT CLASS (NeoPixel version)
# ============================================================
class HeartbeatNeoPixel:
def __init__(self, neopixel_obj, pixel_index=0, color=(255, 0, 0),
brightness=50, interval_ms=500):
self.np = neopixel_obj
self.index = pixel_index
self.color = color
self.brightness = brightness
self.interval = interval_ms
self.state = False
self.last_time = time.ticks_ms()
def apply_brightness(self, c):
r, g, b = c
factor = self.brightness / 100
return (int(r * factor), int(g * factor), int(b * factor))
def update(self):
now = time.ticks_ms()
if time.ticks_diff(now, self.last_time) >= self.interval:
self.state = not self.state
self.last_time = now
if self.state:
self.np[self.index] = self.apply_brightness(self.color)
else:
self.np[self.index] = (0, 0, 0)
self.np.write()
# ============================================================
# NEOPIXEL SETUP
# ============================================================
# 3-LED strip on GP17
STRIP_PIN = 17
STRIP_LEDS = 3
strip = neopixel.NeoPixel(machine.Pin(STRIP_PIN), STRIP_LEDS)
# Single heartbeat pixel on GP28
SINGLE_PIN = 28
single = neopixel.NeoPixel(machine.Pin(SINGLE_PIN), 1)
# ============================================================
# BUTTONS (GP20, GP21, GP22)
# ============================================================
button_pins = [20, 21, 22]
buttons = [machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP)
for pin in button_pins]
# ============================================================
# COLOR PALETTE
# ============================================================
colors = [
(255, 0, 0), # 0 Red
(0, 255, 0), # 1 Green
(0, 0, 255), # 2 Blue
(255, 255, 0), # 3 Yellow
(0, 255, 255), # 4 Cyan
(255, 0, 255), # 5 Magenta
(255, 128, 0), # 6 Orange
(128, 0, 255), # 7 Purple
(255, 20, 147), # 8 Pink
(128, 255, 0), # 9 Lime
(255, 255, 255) # 10 White
]
# ============================================================
# STATE FOR PIXELS 02 (BUTTON CONTROLLED)
# ============================================================
color_index = [0, 0, 0]
brightness = [50, 50, 50]
last_state = [1, 1, 1]
press_time = [0, 0, 0]
# ============================================================
# HEARTBEAT PIXEL CONFIG
# ============================================================
FLASH_COLOR_INDEX = 7 # choose from palette (010)
FLASH_BRIGHTNESS = 100
FLASH_INTERVAL_MS = 500 # speed of heartbeat blink
heartbeat = HeartbeatNeoPixel(
neopixel_obj=single,
pixel_index=0,
color=colors[FLASH_COLOR_INDEX],
brightness=FLASH_BRIGHTNESS,
interval_ms=FLASH_INTERVAL_MS
)
# ============================================================
# HELPER FUNCTIONS
# ============================================================
def apply_brightness(color, level):
r, g, b = color
factor = level / 100
return (int(r * factor), int(g * factor), int(b * factor))
def update_strip():
for i in range(STRIP_LEDS):
strip[i] = apply_brightness(colors[color_index[i]], brightness[i])
strip.write()
# ============================================================
# INITIAL STATE
# ============================================================
update_strip()
# ============================================================
# MAIN LOOP
# ============================================================
while True:
now = time.ticks_ms()
# --------------------------------------------
# BUTTON HANDLING FOR PIXELS 0, 1, 2
# --------------------------------------------
for i in range(3):
state = buttons[i].value()
if last_state[i] == 1 and state == 0:
press_time[i] = now
if last_state[i] == 0 and state == 1:
duration = time.ticks_diff(now, press_time[i])
if duration > 500:
# LONG PRESS → brightness
brightness[i] += 10
if brightness[i] > 100:
brightness[i] = 10
else:
# SHORT PRESS → next color
color_index[i] = (color_index[i] + 1) % len(colors)
update_strip()
time.sleep_ms(200) # debounce
last_state[i] = state
# --------------------------------------------
# HEARTBEAT PIXEL UPDATE (GP28)
# --------------------------------------------
heartbeat.update()
time.sleep_ms(10)
ex[i] = (color_index[i] + 1) % len(colors)
update_strip()
time.sleep_ms(200) # debounce
last_state[i] = state
# -----------------------------
# FLASHING SINGLE PIXEL (GP28)
# -----------------------------
# if time.ticks_diff(now, last_flash_time) >= FLASH_INTERVAL_MS:
# flash_on = not flash_on
# last_flash_time = now
#
# if flash_on:
# single_on()
# else:
# single_off()
time.sleep_ms(10)

174
Maker_Pico_Box/main5.py Normal file
View File

@@ -0,0 +1,174 @@
import machine
import time
import neopixel
# ============================================================
# HEARTBEAT CLASS (smooth fading version)
# ============================================================
class HeartbeatFadeNeoPixel:
def __init__(self, neopixel_obj, pixel_index=0, color=(255, 0, 0),
max_brightness=100, step=2, interval_ms=20):
self.np = neopixel_obj
self.index = pixel_index
self.color = color
self.max_brightness = max_brightness
self.step = step # how fast brightness changes
self.interval = interval_ms
self.brightness = 0
self.direction = 1 # 1 = going up, -1 = going down
self.last_time = time.ticks_ms()
def apply_brightness(self, c, level):
r, g, b = c
factor = level / 100
return (int(r * factor), int(g * factor), int(b * factor))
def update(self):
now = time.ticks_ms()
if time.ticks_diff(now, self.last_time) >= self.interval:
self.last_time = now
# Update brightness
self.brightness += self.direction * self.step
# Bounce at limits
if self.brightness >= self.max_brightness:
self.brightness = self.max_brightness
self.direction = -1
if self.brightness <= 0:
self.brightness = 0
self.direction = 1
# Apply brightness
self.np[self.index] = self.apply_brightness(self.color, self.brightness)
self.np.write()
# ============================================================
# NEOPIXEL SETUP
# ============================================================
# 3-LED strip on GP17
STRIP_PIN = 17
STRIP_LEDS = 3
strip = neopixel.NeoPixel(machine.Pin(STRIP_PIN), STRIP_LEDS)
# Single heartbeat pixel on GP28
SINGLE_PIN = 28
single = neopixel.NeoPixel(machine.Pin(SINGLE_PIN), 1)
# ============================================================
# BUTTONS (GP20, GP21, GP22)
# ============================================================
button_pins = [20, 21, 22]
buttons = [machine.Pin(pin, machine.Pin.IN, machine.Pin.PULL_UP)
for pin in button_pins]
# ============================================================
# COLOR PALETTE
# ============================================================
colors = [
(0, 0, 0), # Off
(255, 0, 0), # Red
(0, 255, 0), # Green
(0, 0, 255), # Blue
(255, 255, 0), # Yellow
(0, 255, 255), # Cyan
(255, 0, 255), # Magenta
(255, 128, 0), # Orange
(128, 0, 255), # Purple
(255, 20, 147), # Pink
(128, 255, 0), # Lime
(255, 255, 255), # White
]
# ============================================================
# STATE FOR PIXELS 02 (BUTTON-CONTROLLED)
# ============================================================
color_index = [0, 0, 0]
brightness = [50, 50, 50]
last_state = [1, 1, 1]
press_time = [0, 0, 0]
# ============================================================
# HEARTBEAT PIXEL CONFIG (smooth fade)
# ============================================================
FLASH_COLOR_INDEX = 1 # Choose from palette
FLASH_MAX_BRIGHTNESS = 20 # Peak brightness for fade
FLASH_STEP = 0.5 # Speed of fade
FLASH_INTERVAL_MS = 30 # Lower = smoother animation
heartbeat = HeartbeatFadeNeoPixel(
neopixel_obj=single,
pixel_index=0,
color=colors[FLASH_COLOR_INDEX],
max_brightness=FLASH_MAX_BRIGHTNESS,
step=FLASH_STEP,
interval_ms=FLASH_INTERVAL_MS
)
# ============================================================
# HELPERS
# ============================================================
def apply_brightness(color, level):
r, g, b = color
factor = level / 100
return (int(r * factor), int(g * factor), int(b * factor))
def update_strip():
for i in range(STRIP_LEDS):
strip[i] = apply_brightness(colors[color_index[i]], brightness[i])
strip.write()
# ============================================================
# INITIAL STATE
# ============================================================
update_strip()
# ============================================================
# MAIN LOOP
# ============================================================
while True:
now = time.ticks_ms()
# --------------------------------
# BUTTON HANDLING FOR 3-LED STRIP
# --------------------------------
for i in range(3):
state = buttons[i].value()
if last_state[i] == 1 and state == 0:
press_time[i] = now
if last_state[i] == 0 and state == 1:
duration = time.ticks_diff(now, press_time[i])
if duration > 500:
brightness[i] += 10
if brightness[i] > 100:
brightness[i] = 10
else:
color_index[i] = (color_index[i] + 1) % len(colors)
update_strip()
time.sleep_ms(200)
last_state[i] = state
# ----------------------------
# SMOOTH HEARTBEAT UPDATE
# ----------------------------
heartbeat.update()
time.sleep_ms(10)

View File

@@ -0,0 +1,46 @@
import machine
import neopixel
import time
# NeoPixel setup
NUM_LEDS = 8
np = neopixel.NeoPixel(machine.Pin(17), NUM_LEDS) # 28
# Button on GP22 (active LOW)
button = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_UP)
# Color list (R, G, B)
colors = [
(255, 0, 0), # Red
(0, 255, 0), # Green
(0, 0, 255), # Blue
(255, 255, 0), # Yellow
(255, 0, 255), # Magenta
(0, 255, 255), # Cyan
(255, 255, 255) # White
]
current_color = 0
last_state = 1 # button not pressed
def show_color(color):
for i in range(NUM_LEDS):
np[i] = color
np.write()
# Initial color
show_color(colors[current_color])
while True:
state = button.value()
# Detect button press (HIGH → LOW)
if last_state == 1 and state == 0:
current_color = (current_color + 1) % len(colors)
show_color(colors[current_color])
time.sleep_ms(200) # Debounce delay
last_state = state
time.sleep_ms(10)

29
Maker_Pico_Box/rainbow.py Normal file
View File

@@ -0,0 +1,29 @@
import machine
import neopixel
import time
# GP28 pin and number of LEDs
pin = 28
num_leds = 8 # change to how many LEDs you have
np = neopixel.NeoPixel(machine.Pin(pin), num_leds)
# Simple color helper
def set_color(r, g, b):
for i in range(num_leds):
np[i] = (r, g, b)
np.write()
# Demo loop
while True:
set_color(255, 0, 0) # Red
time.sleep(1)
set_color(0, 255, 0) # Green
time.sleep(1)
set_color(0, 0, 255) # Blue
time.sleep(1)
set_color(0, 0, 0) # Off
time.sleep(1)