Dimmer
A potentiometer (slider or rotary) is used to control the brightness (intensity register) of a light bulb. This example uses a Raspberry Pi pico but could be redone using other devices.
import { pins } from "@dsboard/pico"
import { startLightBulb, startPotentiometer } from "@devicescript/servers"
// starting a potentiometer driver on GP26
// pinout https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#pinout-and-design-files
const slider = startPotentiometer({
pin: pins.GP26,
})
// starting a dimmieable light on pin GP2
const led = startLightBulb({
pin: pins.GP7,
dimmable: true,
})
// subscribing to the slider readings and sending them to the intensity register
slider.reading.subscribe(async level => {
await led.intensity.write(level)
})