Kitchen Lighting
Kitchen Lighting
This was a quick project that was too little effort to throw together, that it wasn’t worth adding to the main site. So here we go on /blog.
There’s this section of my kitchen that doesn’t get quite enough light and I’m far too lazy to walk over to the kitchen switch to turn on the overheads. Sometimes I just want to slice a quarter of an onion or fill my bong real quick. Those things don’t need flood lights and a small hike, when focused LED light would get the job done.
So I added an LED strip to the bottom of this shelf to toggle a bright white glow onto the counter below. I originally had it timed, like my stairway lights, but it was too distracting when my office looks like Tron. A bright white light, among multiple video game colors and ambient lights, doesn’t exactly add to the aesthetics.
So, I added a pushbutton toggle, in the form of a blue arcade button. There are plenty of them lying around from other projects and they needed to get some use. The script below listens for a button push, then toggles to the next state. The same pin0
applies here, but I’ve added the arcade button to pin19
(GPIO14) and the ground pin on the Pico. This could have easily been done with a basic RP2040, but I didn’t feel like switching them out. Either one is (before inflation) ~$5, so whatever. I’ll just grab more another time.
Switching from PULL_DOWN
to PULL_UP
fixed a problem I was stuck on for a while. Here’s the difference:
- Pull-Up: Pin defaults to high, pulled to low when externally connected to ground.
- Pull-Down: Pin defaults to low, pulled to high when externally connected to voltage supply.
main.py
import machine
import neopixel
# LEDs
num_leds = 30 # Number of LEDs in your strip
pin = 0 # GPIO pin where the LED strip is connected
# print(f"Setting up {num_leds} LEDs on pin {pin}") # Debugging
np = neopixel.NeoPixel(machine.Pin(pin), num_leds)
# Button
button_pin = 14 # GPIO14 (physical pin 19)
# print(f"Setting up button on GPIO pin {button_pin}") # Debugging
button = machine.Pin(button_pin, machine.Pin.IN, machine.Pin.PULL_UP)
led_on = False
def set_led_strip_color(r, g, b):
for i in range(num_leds):
np[i] = (r, g, b)
np.write()
print(f"LED color set to ({r}, {g}, {b})") # Debugging
def toggle_led_strip():
global led_on
if led_on:
set_led_strip_color(0, 0, 0)
print("LED strip off") # Debugging
else:
set_led_strip_color(255, 255, 255)
print("LED strip on") # Debugging
led_on = not led_on
while True:
if button.value() == 0: # Button pressed (inverted logic)
print("Button pressed") # Debugging
toggle_led_strip()
while button.value() == 0:
time.sleep(0.01) # Wait for the button to be released
time.sleep(0.2) # Additional debounce delay
else:
print("Button not pressed") # Debugging
# Small delay to avoid high CPU usage
time.sleep(0.2)
It might look like a mess now, but I’ll make it look cleaner sometime in the future. For now, it’s functional. A flat, 90° power plug will be first to get swapped out.