Potentiometers

Available methods

Configuration

  • setAnalogMax(analogMax) - Set the maximum value returned by analogRead(). Defaults to 1023 (10-bit ADC). Set to 4095 for boards with 12-bit ADCs (ESP32, Teensy, RP2040, STM32, etc.).
  • setMultiplexer(&mux) - Sets the multiplexer that the potentiometer subscribes to.
  • setGroup(&group) - Register the potentiometer to a group.

Core

  • process() - Polls the potentiometer and handles all its functionality (used in the loop method).
  • setRawValue(rawValue) - Provide an externally-read raw ADC value. Use this instead of process() when reading the ADC externally (e.g., via DMA or async ADC). Smoothing and value change detection are still applied.
  • storeRaw(rawValue) - Store a raw ADC value from an ISR or DMA callback. Call this from your timer ISR or DMA completion handler. It stores the value in an internal volatile buffer without any processing. The next call to process() will consume the stored value and apply smoothing, mapping, and change detection as normal.

Event handlers

  • setOnValueChange(handler) - Sets the onValueChange handler. Called as soon as the reading of the potentiometer changes.

State

  • getValue() - Retrieves the current value of the potentiometer.
  • getPercentage() - Retrieves the current value as a percentage of the maximum output value (0 - 100).
  • getMaxOutputValue() - Returns the maximum output value, as set in the constructor.
  • getNormalized() - Retrieves the value as 0.0 - 1.0. Pass a curve to shape it: getNormalized(CtrlTaper::Log) (audio taper, slow start, for volume; halfway is about 0.09) or getNormalized(CtrlTaper::AntiLog) (fast start; halfway is about 0.91). The default is CtrlTaper::Linear.
  • hasChanged() - Checks if the value changed since the last call. Reports each change once; safe to call from an interrupt, e.g. an audio callback.
  • getAnalogMax() - Get the maximum value returned by analogRead().
  • isEnabled() - Checks if the potentiometer is enabled.
  • isDisabled() - Checks if the potentiometer is disabled.
  • isMuxed() - Checks if the potentiometer is currently attached to a multiplexer.
  • isGrouped() - Checks if the potentiometer is currently added to a group.
  • enable() - Enables the potentiometer.
  • disable() - Disables the potentiometer.

Custom properties

  • setInteger("id", 0) - Define an integer. First parameter is the name, second is the value.
  • setString("name", "Potentiometer") - Define a string. First parameter is the name, second is the value.
  • setBoolean("active", true) - Define a boolean. First parameter is the name, second is the value.
  • getInteger("id") - Get the value of an integer.
  • getString("name") - Get the value of a string.
  • getBoolean("active") - Get the value of a boolean.
  • setProperties(storage) - Optional: use your own CtrlProperties storage instead of allocating it on first use.

An object only reserves memory for its properties the first time you set one (max 8 properties per object, names up to 15 characters, string values up to 20 characters). If your project must avoid the heap, declare the storage yourself: CtrlProperties properties; potentiometer.setProperties(properties);

Previous
Dual action button