Henglos IO
Built-in packages

Joystick

A 2-axis analog joystick with a push button (KY-023 and the like — VRx, VRy, SW).

A 2-axis analog joystick with a push button (KY-023 and the like — VRx, VRy, SW). Read gives x and y from -100 to 100, Direction branches Up, Down, Left, Right or Center, Button branches on the push button, and Calibrate sets where the stick rests.

@henglosio/component-joystickv1.0.0platform ^1.0.0
NodeKindWhat it does
ReadActionWhere the stick is — x and y from -100 to 100 (0 at rest), how far and which way it's pushed, and whether its button is down.
DirectionActionBranches on where the stick points — Up, Down, Left, Right, or Center while it's near the middle.
ButtonActionBranches on the stick's push button — Pressed or Released, read twice Debounce apart so its chatter doesn't count.
CalibrateActionTakes where the stick rests now as its center, for Read and Direction on the same pins.

Actions

Read

Where the stick is — x and y from -100 to 100 (0 at rest), how far and which way it's pushed, and whether its button is down.

Settings

SettingTypeDefaultWhat it's for
X PinPin (analog in)GPIO34Required. Board pin wired to the joystick's VRx — an analog input; GPIO32-39 keep working with Wi-Fi on.
Y PinPin (analog in)GPIO35Required. Board pin wired to the joystick's VRy — an analog input; GPIO32-39 keep working with Wi-Fi on.
Button PinPin (digital in + digital out)—Board pin wired to the joystick's SW, to publish pressed — leave it empty if you don't use the button. Not GPIO34-39 (no pull-up).
Dead ZoneNumber (0 to 90)10Advanced. How far from the center still reads as 0, in % of the travel — 0 to 90. Raise it if the stick drifts at rest.
Invert XOn / offOffAdvanced. Swap left and right — for a joystick mounted the other way round.
Invert YOn / offOffAdvanced. Swap up and down — for a module whose Y reads the other way, or one mounted upside down.
SamplesNumber (1 to 64)8Advanced. Readings averaged per axis, 1 to 64 — more is steadier, a little slower.

Publishes

OutputTypeWhat it is
xfloatLeft (-100) to right (100), 0 at rest.
yfloatDown (-100) to up (100), 0 at rest.
magnitudefloatHow far the stick is pushed, 0 to 100, whichever way.
anglefloatWhich way it's pushed, in degrees — 0 right, 90 up, 180 left, 270 down. Only while it's pushed.
pressedboolWhether the button is down — with a Button Pin.
raw_xintThe voltage read on X, 0 (0 V) to 65535 (3.3 V) — to check the wiring. At rest it should be near the middle.
raw_yintThe voltage read on Y, 0 (0 V) to 65535 (3.3 V) — to check the wiring. At rest it should be near the middle.

Direction

Branches on where the stick points — Up, Down, Left, Right, or Center while it's near the middle. Split evenly: Center is a circle of radius Threshold, and each way a 90° slice of the stick's angle — a diagonal goes to the slice it falls in. A board connects 4 outputs of an action by default: leave one unconnected, or raise Outputs per action in Platform settings.

Ends on Up, Down, Left, Right, Center — or Fallback when it can't run.

Settings

SettingTypeDefaultWhat it's for
X PinPin (analog in)GPIO34Required. Board pin wired to the joystick's VRx — an analog input; GPIO32-39 keep working with Wi-Fi on.
Y PinPin (analog in)GPIO35Required. Board pin wired to the joystick's VRy — an analog input; GPIO32-39 keep working with Wi-Fi on.
ThresholdNumber (1 to 100)50How far the stick has to be pushed to count as a direction, in % — 1 to 100. Below it, Center.
Dead ZoneNumber (0 to 90)10Advanced. How far from the center still reads as 0, in % of the travel — 0 to 90. Raise it if the stick drifts at rest.
Invert XOn / offOffAdvanced. Swap left and right — for a joystick mounted the other way round.
Invert YOn / offOffAdvanced. Swap up and down — for a module whose Y reads the other way, or one mounted upside down.
SamplesNumber (1 to 64)8Advanced. Readings averaged per axis, 1 to 64 — more is steadier, a little slower.

Publishes

OutputTypeWhat it is
xfloatLeft (-100) to right (100), 0 at rest.
yfloatDown (-100) to up (100), 0 at rest.
anglefloatThe stick's angle, in degrees — 0 right, 90 up, 180 left, 270 down.
directionanyWhere it points, as text — up, down, left, right or center.

Button

Branches on the stick's push button — Pressed or Released, read twice Debounce apart so its chatter doesn't count.

Ends on Pressed, Released — or Fallback when it can't run.

Settings

SettingTypeDefaultWhat it's for
Button PinPin (digital in + digital out)GPIO32Required. Board pin wired to the joystick's SW — not GPIO34-39 (no pull-up).
DebounceNumber (0 to 500)20Advanced. How long the press has to hold to count, in ms — 0 to 500. 0 reads it once.

Publishes

OutputTypeWhat it is
pressedboolWhether the button is down.

Calibrate

Takes where the stick rests now as its center, for Read and Direction on the same pins. Without it, the first reading at rest after the board starts is the center — fine as long as nobody's touching the stick then.

Settings

SettingTypeDefaultWhat it's for
X PinPin (analog in)GPIO34Required. Board pin wired to the joystick's VRx — an analog input; GPIO32-39 keep working with Wi-Fi on.
Y PinPin (analog in)GPIO35Required. Board pin wired to the joystick's VRy — an analog input; GPIO32-39 keep working with Wi-Fi on.

Publishes

OutputTypeWhat it is
center_xintX's voltage at rest, 0 (0 V) to 65535 (3.3 V).
center_yintY's voltage at rest, 0 (0 V) to 65535 (3.3 V).

On this page