SBK_BarDrive Library 2.1.0
LED bar meter control and queued animations for Arduino
Loading...
Searching...
No Matches
SBK_BarMeter< DriverT > Class Template Reference

Template class for controlling segment-based LED bar meters using row/column mappings. More...

#include <SBK_BarDrive.h>

Public Member Functions

 SBK_BarMeter (DriverT *driver, uint8_t devIdx, MatrixPreset matrixPreset=MatrixPreset::BL28_3005SK, BarDirection direction=BarDirection::FORWARD, uint8_t rowOffset=0, uint8_t colOffset=0)
 Construct a SBK_BarMeter using a predefined matrix-style layout.
 SBK_BarMeter (DriverT *driver, uint8_t devIdx, uint8_t rowsNum, uint8_t colsNum, BarDirection direction=BarDirection::FORWARD, uint8_t rowOffset=0, uint8_t colOffset=0)
 Construct a SBK_BarMeter with a custom matrix size (rows × columns layout).
 SBK_BarMeter (DriverT *driver, uint8_t devIdx, uint8_t segsNum, BarDirection direction=BarDirection::FORWARD, uint8_t segOffset=0)
 Construct a SBK_BarMeter with a fixed number of vertical segments (non-matrix layout).
template<size_t N>
 SBK_BarMeter (DriverT *driver, uint8_t devIdx, const uint8_t(&mapping)[N][3], BarDirection direction=BarDirection::FORWARD, bool progmem=false, uint8_t rowOffset=0, uint8_t colOffset=0)
 Construct a SBK_BarMeter using a custom pixel mapping array.
 ~SBK_BarMeter ()
void show ()
 Push the current LED state buffer to the physical display.
void clear ()
 Clear all bar segments.
void setDirection (BarDirection dir)
 Set the bar fill direction.
BarDirection getDirection () const
 Get the current bar fill direction.
uint8_t getSegsNum () const
 Get the total number of segments in the bar.
void debugSegmentMapping (Stream &stream=Serial)
 Print the segment-to-device mapping for debugging purposes.
void setPixel (uint8_t segment, uint8_t state)
 Set the on/off state of a logical segment (LED).
uint8_t getPixelState (uint8_t segment) const
 Get the current state of a bar segment (pixel).
SBK_BarMetersetSegmentOffset (uint8_t offset)
 Apply a segment-wise offset (shifts segment index before mapping to row/col).
SBK_BarMetersetMatrixOffset (uint8_t rowOffset, uint8_t colOffset)
 Apply a matrix-style physical offset for row/column positioning.

Detailed Description

template<typename DriverT>
class SBK_BarMeter< DriverT >

Template class for controlling segment-based LED bar meters using row/column mappings.

This class provides flexible control over bar meter displays by mapping logical segments to physical LED positions defined by [device, row, col] coordinates. It supports:

  • Direction inversion (FORWARD or REVERSE)
  • Custom or preset segment layouts
  • Matrix-style or linear segment addressing
  • Split bar meters spanning multiple devices of the same driver type

Compatible with any driver that implements the SBK display driver API, including SBK_MAX72xx (hardware/software SPI) and SBK_HT16K33 (I2C).

Typically used via the higher-level SBK_BarDrive wrapper for simplified control and animation support.

Definition at line 125 of file SBK_BarDrive.h.

Constructor & Destructor Documentation

◆ SBK_BarMeter() [1/4]

template<typename DriverT>
SBK_BarMeter< DriverT >::SBK_BarMeter ( DriverT * driver,
uint8_t devIdx,
MatrixPreset matrixPreset = MatrixPreset::BL28_3005SK,
BarDirection direction = BarDirection::FORWARD,
uint8_t rowOffset = 0,
uint8_t colOffset = 0 )
inline

Construct a SBK_BarMeter using a predefined matrix-style layout.

Parameters
driverPointer to the LED driver (e.g., SBK_MAX72xx or SBK_HT16K33).
devIdxIndex of the first device in the chain (0–7).
matrixPresetPreset mapping type from the MatrixPreset enum.
directionBar fill direction (FORWARD or REVERSE). Default is FORWARD.
rowOffsetOptional row offset (if the matrix is not wired to the first row). Default is 0.
colOffsetOptional column offset (if the matrix is not wired to the first column). Default is 0.

This constructor simplifies setup by using a predefined segment-to-row/column mapping, useful for SBK matrix-type bar meters such as SK28 or SA28 models.

Definition at line 141 of file SBK_BarDrive.h.

References BL28_3005SK, and FORWARD.

Referenced by setMatrixOffset(), and setSegmentOffset().

◆ SBK_BarMeter() [2/4]

template<typename DriverT>
SBK_BarMeter< DriverT >::SBK_BarMeter ( DriverT * driver,
uint8_t devIdx,
uint8_t rowsNum,
uint8_t colsNum,
BarDirection direction = BarDirection::FORWARD,
uint8_t rowOffset = 0,
uint8_t colOffset = 0 )
inline

Construct a SBK_BarMeter with a custom matrix size (rows × columns layout).

Parameters
driverPointer to the LED driver (e.g., SBK_MAX72xx or SBK_HT16K33).
devIdxIndex of the first device in the chain (0–7).
rowsNumNumber of matrix rows (anodes). May span multiple devices vertically.
colsNumNumber of matrix columns (cathodes). Limited to the column capacity of a single device.
directionOptional bar fill direction (FORWARD or REVERSE). Default is FORWARD.
rowOffsetOptional row offset, if the matrix does not begin on the first driver row. Default is 0.
colOffsetOptional column offset, if the matrix does not begin on the first driver column. Default is 0.

This constructor allows you to define a matrix-style bar layout with a custom size and origin, without using a predefined MatrixPreset.

⚠️ Note: Columns cannot be split across devices. Only rows may be extended vertically over multiple devices. Attempting to configure more columns than the driver hardware supports will result in clamping.

Useful for adapting custom matrix layouts or hardware not covered by presets.

Definition at line 189 of file SBK_BarDrive.h.

References FORWARD.

◆ SBK_BarMeter() [3/4]

template<typename DriverT>
SBK_BarMeter< DriverT >::SBK_BarMeter ( DriverT * driver,
uint8_t devIdx,
uint8_t segsNum,
BarDirection direction = BarDirection::FORWARD,
uint8_t segOffset = 0 )
inline

Construct a SBK_BarMeter with a fixed number of vertical segments (non-matrix layout).

Parameters
driverPointer to the LED driver (e.g., SBK_MAX72xx or SBK_HT16K33).
devIdxIndex of the device in the chain (0–7).
segsNumNumber of logical segments (LEDs) in the bar meter.
directionOptional bar fill direction (FORWARD or REVERSE). Default is FORWARD.
segOffsetOptional segment offset if the bar does not start at the first LED output. Default is 0.

This constructor is intended for 1D segment-based bar displays, such as linear bars where each segment is addressed sequentially (not via a 2D matrix).

The segOffset allows you to skip physical outputs if the display is not connected to the first pin of the device. This is useful when sharing a device across multiple bar segments or skipping unused lines.

⚠️ If the specified device index exceeds the available device count, the bar meter is initialized as empty.

Definition at line 235 of file SBK_BarDrive.h.

References FORWARD.

◆ SBK_BarMeter() [4/4]

template<typename DriverT>
template<size_t N>
SBK_BarMeter< DriverT >::SBK_BarMeter ( DriverT * driver,
uint8_t devIdx,
const uint8_t(&) mapping[N][3],
BarDirection direction = BarDirection::FORWARD,
bool progmem = false,
uint8_t rowOffset = 0,
uint8_t colOffset = 0 )
inline

Construct a SBK_BarMeter using a custom pixel mapping array.

Template Parameters
NNumber of segments (inferred automatically from array size).
Parameters
driverPointer to the LED driver (e.g., SBK_MAX72xx or SBK_HT16K33).
devIdxIndex of the first device in the chain (0–7).
mappingArray of [device, row, col] tuples defining the physical LED position for each segment.
directionOptional bar fill direction (FORWARD or REVERSE). Default is FORWARD.
progmemSet to true if the mapping array is stored in PROGMEM (Flash memory). Default is false.
rowOffsetOptional offset to apply to all mapped row indices. Default is 0.
colOffsetOptional offset to apply to all mapped column indices. Default is 0.

This constructor gives you full control over how each logical segment maps to a specific LED location on a matrix or linear display, across one or more devices. It is ideal for:

  • Non-standard matrix layouts
  • Discontinuous or irregular bar patterns
  • Hybrid/multi-device configurations

⚠️ If the specified devIdx is invalid (beyond the available devices), the bar is initialized as empty.

Definition at line 282 of file SBK_BarDrive.h.

References FORWARD.

◆ ~SBK_BarMeter()

template<typename DriverT>
SBK_BarMeter< DriverT >::~SBK_BarMeter ( )
inline

Definition at line 314 of file SBK_BarDrive.h.

Member Function Documentation

◆ clear()

template<typename DriverT>
void SBK_BarMeter< DriverT >::clear ( )
inline

Clear all bar segments.

Definition at line 330 of file SBK_BarDrive.h.

References setPixel().

◆ debugSegmentMapping()

template<typename DriverT>
void SBK_BarMeter< DriverT >::debugSegmentMapping ( Stream & stream = Serial)
inline

Print the segment-to-device mapping for debugging purposes.

This function outputs the resolved mapping of each logical segment index to its corresponding [device, row, column] LED coordinates, based on the internal configuration (preset, custom map, or auto-mapped layout).

Useful for verifying how segments are translated into physical driver outputs, especially when using segment offsets, matrix presets, or split-device configurations.

Parameters
streamReference to a Stream object (e.g., Serial) for printing output. Defaults to Serial if not specified.

Definition at line 367 of file SBK_BarDrive.h.

◆ getDirection()

template<typename DriverT>
BarDirection SBK_BarMeter< DriverT >::getDirection ( ) const
inline

Get the current bar fill direction.

Returns
BarDirection enum.

Definition at line 346 of file SBK_BarDrive.h.

◆ getPixelState()

template<typename DriverT>
uint8_t SBK_BarMeter< DriverT >::getPixelState ( uint8_t segment) const
inline

Get the current state of a bar segment (pixel).

This function returns the last known ON/OFF state of a segment. It queries the driver’s internal buffer (not the physical IC).

Direction and segment mapping are handled internally, so the returned value always corresponds to the logical segment number.

Parameters
segmentIndex of the segment to query (0 to _segsNum - 1).
Returns
1 if the segment is ON, 0 if OFF, or 0 if invalid or driver unavailable.

Definition at line 419 of file SBK_BarDrive.h.

◆ getSegsNum()

template<typename DriverT>
uint8_t SBK_BarMeter< DriverT >::getSegsNum ( ) const
inline

Get the total number of segments in the bar.

Returns
Number of segments.

Definition at line 352 of file SBK_BarDrive.h.

◆ setDirection()

template<typename DriverT>
void SBK_BarMeter< DriverT >::setDirection ( BarDirection dir)
inline

Set the bar fill direction.

Parameters
dirNew direction (FORWARD or REVERSE).

Definition at line 340 of file SBK_BarDrive.h.

◆ setMatrixOffset()

template<typename DriverT>
SBK_BarMeter & SBK_BarMeter< DriverT >::setMatrixOffset ( uint8_t rowOffset,
uint8_t colOffset )
inline

Apply a matrix-style physical offset for row/column positioning.

Parameters
rowOffsetNumber of rows to shift downward.
colOffsetNumber of columns to shift rightward.
Returns
Reference to this instance.

Those offsets are better used with matrix led display matrixPreset, like BL28 matrixPreset where the matrix is not connected to the firsts IC row/column.

Definition at line 456 of file SBK_BarDrive.h.

References SBK_BarMeter().

◆ setPixel()

template<typename DriverT>
void SBK_BarMeter< DriverT >::setPixel ( uint8_t segment,
uint8_t state )
inline

Set the on/off state of a logical segment (LED).

Parameters
segmentIndex of the logical segment to control (0 to getSegNum() - 1).
statetrue to turn the LED on, false to turn it off.

This function resolves the segment index to its corresponding [device, row, col] location and updates the internal buffer of the underlying driver. The change will not be visible until show() is called.

Definition at line 396 of file SBK_BarDrive.h.

Referenced by clear().

◆ setSegmentOffset()

template<typename DriverT>
SBK_BarMeter & SBK_BarMeter< DriverT >::setSegmentOffset ( uint8_t offset)
inline

Apply a segment-wise offset (shifts segment index before mapping to row/col).

Parameters
offsetNumber of segments to skip.
Returns
Reference to this instance.

This offset is better used with a 1 to 1 ICs output to led display where the display do not start on the first IC output.

Definition at line 440 of file SBK_BarDrive.h.

References SBK_BarMeter().

◆ show()

template<typename DriverT>
void SBK_BarMeter< DriverT >::show ( )
inline

Push the current LED state buffer to the physical display.

This flushes the internal buffer of the underlying driver to all connected devices — not just the one associated with this bar meter instance — making any recent changes (e.g., via setPixel() or clear()) visible on the actual hardware.

Internally calls _driver->show() to update the display.

Definition at line 325 of file SBK_BarDrive.h.


The documentation for this class was generated from the following file: