Peli de HalleuxMichał MoskalTom Ball
Published © MIT

DeviceScript - TypeScript for micros

TypeScript for Tiny IoT Devices

BeginnerProtip1 hour4,791
DeviceScript - TypeScript for micros

Things used in this project

Hardware components

RP2040
Raspberry Pi RP2040
×1
LED (generic)
LED (generic)
×1
Resistor 100 ohm
Resistor 100 ohm
×1

Software apps and online services

Microsoft DeviceScript

Story

Read more

Code

Blinky

Typescript
Blinking an LED in TypeScript on a RP2040
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.P1,
})

// 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)

Credits

Peli de Halleux

Peli de Halleux

7 projects • 14 followers
Working on DeviceScript at Microsoft.
Michał Moskal

Michał Moskal

3 projects • 2 followers
Working on programming languages, (embedded) runtimes, and Jacdac at Microsoft Research
Tom Ball

Tom Ball

2 projects • 2 followers
Working on micro:bit, MakeCode, Jacdac, and MicroCode

Comments