Skip to main content

Joystick Widget

⚡ Control

The Joystick widget provides a thumbstick-style XY controller. Dragging the handle sends X and Y coordinates to a virtual pin as a comma-separated pair. Use it to control pan/tilt camera heads, robot drives, or drone gimbal motors.

Default size: 2 × 2 grid cells


Configuration

PropertyTypeDefaultDescription
xMinnumber-100Left extreme value
xMaxnumber100Right extreme value
yMinnumber-100Bottom extreme value
yMaxnumber100Top extreme value
returnToCenterbooleantrueSnap to 0,0 on release
colorhex color#6366F1Handle accent color
DevicedeviceThe device to write to
PinV0V255The virtual pin to write
LabelstringWidget label

Message format

Values are sent as a comma-separated string: "X,Y"

"-45,72"   → x=-45, y=72
"0,0" → centered (released)
"100,-100" → full right, full down

Firmware example

VWIRE_RECEIVE(V0) {
String raw = param.asStr(); // e.g. "-45,72"

int commaIdx = raw.indexOf(',');
int x = raw.substring(0, commaIdx).toInt();
int y = raw.substring(commaIdx + 1).toInt();

// Map to motor speed (-255 to 255 PWM)
int leftMotor = constrain(y + x, -255, 255);
int rightMotor = constrain(y - x, -255, 255);

setMotor(LEFT, leftMotor);
setMotor(RIGHT, rightMotor);
}

Pan-tilt control

Servo panServo, tiltServo;

VWIRE_RECEIVE(V1) {
String raw = param.asStr();
int commaIdx = raw.indexOf(',');
int x = raw.substring(0, commaIdx).toInt(); // -100 to 100
int y = raw.substring(commaIdx + 1).toInt(); // -100 to 100

int pan = map(x, -100, 100, 0, 180);
int tilt = map(y, -100, 100, 0, 180);

panServo.write(pan);
tiltServo.write(tilt);
}

Tips

returnToCenter

Enable returnToCenter for vehicles and drones — the device should stop when the joystick is released. Disable it for absolute-position controls like camera pan where you want the servo to hold position.