Skip to main content

Rotary Encoder

The startRotaryEncoder function starts a Rotary Encoder server on the device and returns a client.

import { gpio } from "@devicescript/core"
import { startRotaryEncoder } from "@devicescript/servers"

const dialA = startRotaryEncoder({
pin0: gpio(2),
pin1: gpio(3),
})

The service instance name is automatically set to the variable name. In this example, it is set to RotadialA.

Options

pin0, pin1

The pin hardware identifiers on which to mount the Rotary Encoder.

clicksPerTurn (optional)

Number of reported clicks per full rotation. Default is 12.

import { gpio } from "@devicescript/core"
import { startRotaryEncoder } from "@devicescript/servers"

const dialA = startRotaryEncoder({
pin0: gpio(2),
pin1: gpio(3),
clicksPerTurn: 24,
})

dense (optional)

Encoder supports "half-clicks". Default is false.

import { gpio } from "@devicescript/core"
import { startRotaryEncoder } from "@devicescript/servers"

const dialA = startRotaryEncoder({
pin0: gpio(2),
pin1: gpio(3),
dense: true,
})

inverted (optional)

Invert direction. Default is false.

import { gpio } from "@devicescript/core"
import { startRotaryEncoder } from "@devicescript/servers"

const dialA = startRotaryEncoder({
pin0: gpio(2),
pin1: gpio(3),
inverted: true,
})