SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AW9364LedDriver Class Reference

Controls LED brightness by generating a specific number of pulses on a GPIO pin. More...

#include <AW9364LedDriver.hpp>

Public Member Functions

void begin (uint8_t pin)
 Initialize the driver for use with a native Arduino pin.
 
void begin (IoExpanderBase &base, uint8_t pin)
 Initialize the driver for use with a GPIO expander pin.
 
void setBrightness (uint8_t value)
 Set the LED brightness level.
 
uint8_t getBrightness () const
 Get the current brightness setting.
 

Protected Member Functions

void _pinMode (uint8_t pin, uint8_t mode)
 Internal helper to set pin mode, handling both native and expander pins.
 
void _digitalWrite (uint8_t pin, uint8_t value)
 Internal helper to write digital value, handling both native and expander pins.
 

Detailed Description

Controls LED brightness by generating a specific number of pulses on a GPIO pin.

The driver toggles the pin rapidly to produce a perceived brightness level. It can operate either directly on an Arduino pin or via an IoExpanderBase (e.g., an I2C GPIO expander).

Warning
When using an I2C expander, the I2C bus speed must be set to 1 MHz; lower speeds will cause insufficient pulse rate and incorrect brightness.

Definition at line 51 of file actuator/AW9364LedDriver.hpp.

Member Function Documentation

◆ _digitalWrite()

void AW9364LedDriver::_digitalWrite ( uint8_t  pin,
uint8_t  value 
)
inlineprotected

Internal helper to write digital value, handling both native and expander pins.

Parameters
pinPin number.
valueHIGH (true) or LOW (false).

Definition at line 183 of file actuator/AW9364LedDriver.hpp.

References IoExpanderBase::digitalWrite().

Referenced by begin(), begin(), and setBrightness().

◆ _pinMode()

void AW9364LedDriver::_pinMode ( uint8_t  pin,
uint8_t  mode 
)
inlineprotected

Internal helper to set pin mode, handling both native and expander pins.

Parameters
pinPin number.
modeINPUT or OUTPUT.

Definition at line 168 of file actuator/AW9364LedDriver.hpp.

References IoExpanderBase::pinMode().

Referenced by begin(), and begin().

◆ begin() [1/2]

void AW9364LedDriver::begin ( IoExpanderBase base,
uint8_t  pin 
)
inline

Initialize the driver for use with a GPIO expander pin.

Parameters
baseReference to an IoExpanderBase instance (e.g., XL9555).
pinPin number on the expander (0‑pinCount‑1).
Warning
The I2C bus speed of the expander MUST be configured to 1 MHz before calling this function. Failure to do so will result in incorrect brightness levels.

Definition at line 77 of file actuator/AW9364LedDriver.hpp.

References _digitalWrite(), and _pinMode().

◆ begin() [2/2]

void AW9364LedDriver::begin ( uint8_t  pin)
inline

Initialize the driver for use with a native Arduino pin.

Parameters
pinArduino pin number (must support OUTPUT mode).

Definition at line 59 of file actuator/AW9364LedDriver.hpp.

References _digitalWrite(), and _pinMode().

Referenced by setup().

◆ getBrightness()

uint8_t AW9364LedDriver::getBrightness ( ) const
inline

Get the current brightness setting.

Returns
uint8_t Current brightness (0‑16).

Definition at line 156 of file actuator/AW9364LedDriver.hpp.

◆ setBrightness()

void AW9364LedDriver::setBrightness ( uint8_t  value)
inline

Set the LED brightness level.

Brightness is controlled by the number of pulses generated. A value of 0 turns the LED off (pin LOW). Non‑zero values are mapped to a number of pulses that adjust the brightness upward or downward from the current setting. Pulses are generated by quickly toggling the pin LOW→HIGH.

Parameters
valueDesired brightness (0‑16). Values >16 are clamped to 16.
Note
When using an I2C expander, ensure the bus speed is 1 MHz; otherwise the pulse timing will be incorrect.

Definition at line 99 of file actuator/AW9364LedDriver.hpp.

References _digitalWrite(), i, and MAX_BRIGHTNESS_STEPS.

Referenced by loop().


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