-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdimmer.py
More file actions
28 lines (22 loc) · 906 Bytes
/
Copy pathdimmer.py
File metadata and controls
28 lines (22 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from neopixel import NeoPixel
import time
# --- Configuration ---
ADC_PIN = 26 # Potentiometer connected to GPIO 26 (ADC0)
BUTTON_PIN = 8 # Button connected to GPIO 14
PIXEL_PIN = 25 # Internal Neopixel pin for most RP2040 Matrix boards
np = NeoPixel(Pin(16), 25, bpp = 3) # bpp = bytes per pixel (GRB)
pot = machine.ADC(ADC_PIN)
button = machine.Pin(BUTTON_PIN, machine.Pin.IN, machine.Pin.PULL_UP)
def get_brightness():
# Read ADC (0-65535) and scale it to (0-255) for NeoPixel intensity
# Using a bit-shift or integer division
brightness = pot.read_u16() >> 8
return brightness // 10
# Integer division by 10 to clamp brightness
while True:
brightness = get_brightness()
# Set a color (White in this case) scaled by the potentiometer
# color = (R, G, B)
color = (brightness, brightness, brightness)
np.fill(color)
np.write()