Skip to main content

RotaryEncoder

An incremental rotary encoder - converts angular motion of a shaft to digital signal.

import { RotaryEncoder } from "@devicescript/core"

const rotaryEncoder = new RotaryEncoder()

Registers

reading

Upon device reset starts at 0 (regardless of the shaft position). Increases by 1 for a clockwise "click", by -1 for counter-clockwise.

  • type: Register<number> (packing format i32)

  • read only

import { RotaryEncoder } from "@devicescript/core"

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

const rotaryEncoder = new RotaryEncoder()
// ...
rotaryEncoder.reading.subscribe(async (value) => {
...
})
note

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

clicksPerTurn

This specifies by how much position changes when the crank does 360 degree turn. Typically 12 or 24.

  • type: Register<number> (packing format u16)

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

  • read only

import { RotaryEncoder } from "@devicescript/core"

const rotaryEncoder = new RotaryEncoder()
// ...
const value = await rotaryEncoder.clicksPerTurn.read()
note

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

clicker

The encoder is combined with a clicker. If this is the case, the clicker button service should follow this service in the service list of the device.

  • 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 { RotaryEncoder } from "@devicescript/core"

const rotaryEncoder = new RotaryEncoder()
// ...
const value = await rotaryEncoder.clicker.read()
note

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