SBK_HT16K33 library 2.0.0
Standalone Arduino library to control HT16K33 LED matrices or bar meters via I2C. Can be used directly or as a driver for SBK_BarDrive animations.
Loading...
Searching...
No Matches
SBK_HT16K33 Class Reference

I2C driver wrapper for HT16K33 compatible with SBK_BarMeter and SBK_BarDrive. More...

#include <SBK_HT16K33.h>

Public Member Functions

 SBK_HT16K33 (uint8_t devsNum=1)
 Construct a new SBK_HT16K33 instance.
 ~SBK_HT16K33 ()
 Destructor. Frees allocated buffer memory.
void setDriverRows (uint8_t devIdx, uint8_t rowsCount=8)
 Set the number of active rows (anode outputs) for a specific HT16K33 device.
uint8_t maxRows (uint8_t devIdx) const
 Returns the number of active row lines (anode outputs) for a specific HT16K33 device.
uint8_t maxColumns () const
 Returns the number of active column lines (cathode outputs = C0–C7) configured for this instance.
uint8_t maxSegments (uint8_t devIdx) const
 Returns the total number of addressable LED segments for the specified device.
uint8_t setAddress (uint8_t devIdx, uint8_t addr)
 Set the I2C address for a specific HT16K33 device.
void begin ()
 Initialize the HT16K33 device at a given I2C address.
void clear (uint8_t devIdx)
 Clear the display buffer for the specified device.
void clear ()
 Clear the display buffers for all devices.
void setBrightness (uint8_t devIdx, uint8_t brightness)
 Set the brightness level (0–15) for a specific device.
void setBrightness (uint8_t brightness)
 Set the brightness level (0–15) for all devices.
uint8_t devsNum () const
 Returns the number of active HT16K33 devices managed by this driver instance.
void setLed (uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx, bool state)
 Set the state of an individual LED for a specific device.
bool getLed (uint8_t devIdx, uint8_t rowIdx, uint8_t colIdx) const
 Get the current state of an LED from the internal display buffer.
void show (uint8_t devIdx)
 Push the internal display buffer to a specific device.
void show ()
 Push the internal display buffer to all devices.

Detailed Description

I2C driver wrapper for HT16K33 compatible with SBK_BarMeter and SBK_BarDrive.

Constructor & Destructor Documentation

◆ SBK_HT16K33()

SBK_HT16K33::SBK_HT16K33 ( uint8_t devsNum = 1)

Construct a new SBK_HT16K33 instance.

Parameters
devsNumNumber of HT16K33 devices included this driver instance (up to 8). Default is 1.

Member Function Documentation

◆ clear() [1/2]

void SBK_HT16K33::clear ( )

Clear the display buffers for all devices.

This clears the internal LED state buffers across all managed HT16K33 devices. Call .show() afterward to push the changes to the physical displays.

◆ clear() [2/2]

void SBK_HT16K33::clear ( uint8_t devIdx)

Clear the display buffer for the specified device.

Parameters
devIdxIndex of the target device (0–7).

This clears the internal buffer for a single HT16K33 device. Call .show(devIdx) to apply the cleared state to the hardware.

◆ devsNum()

uint8_t SBK_HT16K33::devsNum ( ) const
inline

Returns the number of active HT16K33 devices managed by this driver instance.

Returns
Number of active driver devices for this instance.

◆ getLed()

bool SBK_HT16K33::getLed ( uint8_t devIdx,
uint8_t rowIdx,
uint8_t colIdx ) const

Get the current state of an LED from the internal display buffer.

Parameters
devIdxNot used (for API compatibility only).
rowIdxRow index (0–7).
colIdxColumn index (0–15).
Returns
true if the LED is ON in the internal buffer, false otherwise.

This function reads the last known LED state from the driver’s RAM buffer. It does not query the physical device directly.

Note
For HT16K33:
  • rowIdx maps to Rx lines (anodes)
  • colIdx maps to Cx lines (cathodes) Get LED state at (rowIdx, colIdx)

◆ maxColumns()

uint8_t SBK_HT16K33::maxColumns ( ) const
inline

Returns the number of active column lines (cathode outputs = C0–C7) configured for this instance.

Each column corresponds to a HT16K33 C-line (C0–C7), controlling the cathode side of the LEDs. This defines how many columns (scan lines) are used in the matrix.

Returns
Number of active columns (cathode lines), always 8 for HT16K33.

◆ maxRows()

uint8_t SBK_HT16K33::maxRows ( uint8_t devIdx) const
inline

Returns the number of active row lines (anode outputs) for a specific HT16K33 device.

Parameters
devIdxIndex of the target device (0–7).

Each row corresponds to a physical R-line (R0–R15) on the HT16K33 chip, which controls the anode side of the matrix. The number of active rows depends on the chip package:

  • 20-SOP: 8 rows
  • 24-SOP: 12 rows
  • 28-SOP: 16 rows (full range)

This function returns the current row configuration for the specified device, which can be set using setDriverRows().

Returns
Number of active row lines for the given device.

◆ maxSegments()

uint8_t SBK_HT16K33::maxSegments ( uint8_t devIdx) const
inline

Returns the total number of addressable LED segments for the specified device.

Parameters
devIdxIndex of the device (0–7).

Computed as: maxRows(devIdx) × maxColumns()

This represents the number of individually addressable LEDs (or matrix pixels) available on the specified HT16K33 device, depending on its configured row count.

HT16K33 supports up to:

  • 64 segments (8×8) for 20-SOP
  • 96 segments (12×8) for 24-SOP
  • 128 segments (16×8) for 28-SOP
Returns
Total number of addressable LED segments for the given device.

◆ setAddress()

uint8_t SBK_HT16K33::setAddress ( uint8_t devIdx,
uint8_t addr )

Set the I2C address for a specific HT16K33 device.

By default, device 0 uses address 0x70, device 1 uses 0x71, ..., up to device 7 using 0x77. This function allows you to override that default address mapping.

Parameters
devIdxDevice Index (0–7).
addrI2C address to assign (must be in range 0x70–0x77).
Returns
1 if the address was successfully set, 0 if devIdx or addr is invalid.

◆ setBrightness() [1/2]

void SBK_HT16K33::setBrightness ( uint8_t brightness)

Set the brightness level (0–15) for all devices.

Parameters
brightnessBrightness level (0 = dimmest, 15 = brightest).

This function applies the specified brightness level to all HT16K33 devices managed by this driver instance.

◆ setBrightness() [2/2]

void SBK_HT16K33::setBrightness ( uint8_t devIdx,
uint8_t brightness )

Set the brightness level (0–15) for a specific device.

Parameters
devIdxIndex of the target device (0–7).
brightnessBrightness level (0 = dimmest, 15 = brightest).

This function sets the brightness for a single HT16K33 device. It is API-compatible with the MAX72xx interface used in SBK_BarDrive.

◆ setDriverRows()

void SBK_HT16K33::setDriverRows ( uint8_t devIdx,
uint8_t rowsCount = 8 )
inline

Set the number of active rows (anode outputs) for a specific HT16K33 device.

Parameters
devIdxIndex of the target device (0–7).
rowsCountNumber of active row lines (must be 8, 12, or 16).Default is 8.

HT16K33 comes in multiple package variants that determine the number of available anode outputs:

  • 20-SOP → 8 rows (R0–R7)
  • 24-SOP → 12 rows (R0–R11)
  • 28-SOP → 16 rows (R0–R15)

Use this function to limit the active row count per device if you're using a smaller variant.

Note
Invalid device indices or unsupported row counts are ignored.

◆ setLed()

void SBK_HT16K33::setLed ( uint8_t devIdx,
uint8_t rowIdx,
uint8_t colIdx,
bool state )

Set the state of an individual LED for a specific device.

Parameters
devIdxIndex of the target device (0–7).
rowIdxRow index (0 to maxRows(devIdx) - 1).
colIdxColumn index (0 to maxColumns() - 1).
statetrue = LED ON, false = LED OFF.

This function updates the internal buffer for a single LED on a specific HT16K33 device. You must call .show() to apply the changes to the physical display.

Note
For HT16K33:
  • rowIdx corresponds to Rx pins (anode, V+ source)
  • colIdx corresponds to Cx pins (cathode, GND sink) Set LED at (rowIdx, colIdx)

◆ show() [1/2]

void SBK_HT16K33::show ( )

Push the internal display buffer to all devices.

This sends the buffered LED states to all HT16K33 devices managed by this driver. Use this to update the entire display after modifying any LED states.

◆ show() [2/2]

void SBK_HT16K33::show ( uint8_t devIdx)

Push the internal display buffer to a specific device.

Parameters
devIdxIndex of the target device (0–7).

This sends the buffered LED states to the physical HT16K33 display for the specified device only.

Note
This function must be called after setLed() or clear() to reflect changes on the hardware. Push buffer to display for one device

The documentation for this class was generated from the following files:
  • C:/Users/sbara/OneDrive/Documents/GitHub/SBK_HT16K33/src/SBK_HT16K33.h
  • C:/Users/sbara/OneDrive/Documents/GitHub/SBK_HT16K33/src/SBK_HT16K33.cpp