Skip to content

AnalogCalibration

Namespace: CtrlDS4

struct AnalogCalibration

Readings of an analog pin that match the ends of a control, for Controller::bindAnalog().

Sensors and potentiometers rarely reach the ends of the analogRead() range, which would keep the control from reaching its ends too. Give the readings measured at the ends instead.

// Potentiometer reading 120 fully left and 900 fully right, ignoring 5% around the center
CtrlDS4::AnalogCalibration calibration(120, 900, 0.05);
controller.bindAnalog(CtrlDS4::LeftStickX, A0, calibration);

Constructors

AnalogCalibration(uint16_t, uint16_t, float)

explicit AnalogCalibration(uint16_t minReading = 0, uint16_t maxReading = ANALOG_READ_MAX, float deadzone = 0)

Builds a calibration.

Parameters

Fields

minReading

uint16_t minReading

Reading at the start of the control: released trigger, start of an axis half, or left (X) or down (Y) end of a full axis. Can be above maxReading, to invert the control.

maxReading

uint16_t maxReading

Reading at the end of the control: fully pressed trigger, end of an axis half, or right (X) or up (Y) end of a full axis.

deadzone

float deadzone

Part of the control near rest that reads as exactly at rest, from 0 to 1, so the control doesn't drift. Around the center for a full axis. The rest of the range is scaled to still reach the end.