Skip to main content

Commands

Let's assume that 1400 hPa is a threshold high enough to detect a user blowing on the sensor; then we can add code to generate a mouse click.

1400 is rater arbitrary and this is the kind of constants that you will want to tune using the actual hardware sensors, not just a simulator.

if (pressure > 1400) {
await mouse.setButton(ds.HidMouseButton.Left, ds.HidMouseButtonEvent.Click)
}

The full sample looks like this.

console.log("starting...")
const sensor = new ds.AirPressure()
const mouse = new ds.HidMouse()
// listen for pressure changes
sensor.reading.subscribe(async pressure => {
console.log(pressure)
// user blows in straw
if (pressure > 1400) {
// click!
console.log(`click!`)
await mouse.setButton(
ds.HidMouseButton.Left,
ds.HidMouseButtonEvent.Click
)
// debouncing
await ds.sleep(50)
}
})

To get better debouncing, see observables.