Skip to main content

Button LED

This sample toggles a LED on/off by listening on the down events emitted by a button.

import { pins } from "@dsboard/esp32c3_bare"
import { startLightBulb, startButton } from "@devicescript/servers"

const led = startLightBulb({
pin: pins.P2,
})
const button = startButton({
pin: pins.P5,
})
console.log(`press button to toggle light`)
// listen for button down events
button.down.subscribe(async () => {
// toggle light on/off
console.log(`toggle`)
await led.toggle()
})