MicroPythonRaspberry Pi PicoExact chip

MicroPython: knob dimmer

A potentiometer on GP26 sets an LED’s brightness on GP15 with PWM.

MicroPython: knob dimmer in Argynix Lab

The code

main.pyPython
# A potentiometer on GP26 (ADC 0) sets the brightness of the LED on GP15 (PWM).
# Turn the knob while it runs.
from machine import ADC, PWM, Pin
import time

knob = ADC(26)
led = PWM(Pin(15))
led.freq(1000)
while True:
    level = knob.read_u16()
    led.duty_u16(level)
    print("level", level * 100 // 65535, "%")
    time.sleep(0.2)