microsoft / devicescript

TypeScript for Tiny IoT Devices (ESP32, RP2040, ...)
https://microsoft.github.io/devicescript/
MIT License
3.27k stars 118 forks source link

something like this? #220

Closed tballmsft closed 1 year ago

tballmsft commented 1 year ago

Here's start of a very simple sample with input (sensor) and output (traffic light).


console.log("starting...")
const temp = new ds.Temperature()
const light = new ds.TrafficLight()
temp.temperature.subscribe(async t => {
    console.log(t)
    await light.green.write(false)
    await light.yellow.write(false)
    await light.red.write(false)
    if (t > 30) {
        await light.red.write(true)
    } else if (t > 20) {
        await light.yellow.write(true)
    } else {
        await light.green.write(true)
    }
})
tballmsft commented 1 year ago

image

pelikhan commented 1 year ago

not sure what the ask is.

pelikhan commented 1 year ago

added sample https://github.com/microsoft/devicescript/commit/2544de05e56455a0f7abd3252adb1a994a6d1920