Blinky
The classic LED blinking program on a Raspberry Pi Pico. The LED is connected to the Pico's pin GP1 (2 on the silk)
import { pins } from "@dsboard/pico"
import { startLightBulb } from "@devicescript/servers"
// start a lightbulb server on pin GP1
// and store client in `led` variable
const led = startLightBulb({
pin: pins.GP1,
})
// start interval timer every 1000ms
setInterval(async () => {
// read current brightness
const brightness = await led.intensity.read()
// toggle on/off
const newbrightness = brightness > 0 ? 0 : 1
// apply new brightness
await led.intensity.write(newbrightness)
}, 1000)
ESP32
The classic LED blinking program on a ESP32
is similar. The LED is connected to the pin A0
.
import { pins } from "@dsboard/adafruit_qt_py_c3"
import { startLightBulb } from "@devicescript/servers"
const lightBulb = startLightBulb({
pin: pins.A0_D0,
})
setInterval(async () => {
await lightBulb.toggle()
}, 500)