Object groups

Available methods

Configuration

  • reserve(capacity) - Pre-allocate capacity for a known number of objects. Call this before adding objects to avoid heap allocations during runtime.

Core

  • process(count) - Polls all objects registered to the group (used in the loop method). When count is 0 (default), all objects are processed. When count is greater than 0, objects are processed in round-robin order for time-sliced control processing.

Event handlers

  • setOnPress(handler) - Set the on press handler (for buttons).
  • setOnRelease(handler) - Set the on release handler (for buttons).
  • setOnDelayedRelease(handler) - Set the on delayed release handler (for buttons).
  • setOnTurnLeft(handler) - Set the on turn left handler (for rotary encoders).
  • setOnTurnRight(handler) - Set the on turn right handler (for rotary encoders).
  • setOnValueChange(handler) - Set the on value change handler (for potentiometers).

State

  • enable() - Enable the group. All objects in the group will be processed.
  • disable() - Disable the group. No objects will be processed while disabled.
  • isEnabled() - Check if the group is enabled.
  • isDisabled() - Check if the group is disabled.

Groupable reference

The following methods are available on the Groupable& reference passed to group event handlers. Use these to identify which object triggered the event and to store/retrieve custom data on each object:

  • isGrouped() - Checks if the object is currently added to a group.
  • setInteger("key", 0) - Define an integer property on an object.
  • setString("key", "value") - Define a string property on an object.
  • setBoolean("key", true) - Define a boolean property on an object.
  • getInteger("key") - Get the value of an integer property.
  • getString("key") - Get the value of a string property.
  • getBoolean("key") - Get the value of a boolean property.

Note: setInteger/setString/setBoolean use fixed-size memory (max 8 properties per object, name up to 15 chars, value up to 20 chars).

Previous
Daisy chaining multiplexers