Skip to main content

Button

A push-button, which returns to inactive position when not operated anymore.

import { Button } from "@devicescript/core"

const button = new Button()

Registers

reading

Indicates the pressure state of the button, where 0 is open.

  • type: Register<number> (packing format u0.16)

  • read only

import { Button } from "@devicescript/core"

const button = new Button()
// ...
const value = await button.reading.read()
  • track incoming values
import { Button } from "@devicescript/core"

const button = new Button()
// ...
button.reading.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

analog

Indicates if the button provides analog pressure readings.

  • type: Register<boolean> (packing format u8)

  • optional: this register may not be implemented

  • constant: the register value will not change (until the next reset)

  • read only

import { Button } from "@devicescript/core"

const button = new Button()
// ...
const value = await button.analog.read()
note

write and read will block until a server is bound to the client.

pressed

Determines if the button is pressed currently.

If the event down or hold is observed, pressed becomes true; if up is observed, pressed becomes false. The client should initialize pressed to false.

  • type: Register<boolean> (packing format u8)

  • read only

import { Button } from "@devicescript/core"

const button = new Button()
// ...
const value = await button.pressed.read()
  • track incoming values
import { Button } from "@devicescript/core"

const button = new Button()
// ...
button.pressed.subscribe(async (value) => {
...
})
note

write and read will block until a server is bound to the client.

Events

down

Emitted when button goes from inactive to active.

button.down.subscribe(() => {

})

up

Emitted when button goes from active to inactive. The 'time' parameter records the amount of time between the down and up events.

button.up.subscribe(() => {

})

hold

Emitted when the press time is greater than 500ms, and then at least every 500ms as long as the button remains pressed. The 'time' parameter records the the amount of time that the button has been held (since the down event).

button.hold.subscribe(() => {

})