PCA9685 PWM

FloatOutput support for an PCA9695 16-Channel PWM Driver.

Example Usage

// Create the PCA9685 Output hub with frequency 500Hz.
auto *pca9685 = App.make_pca9685_component(500.0f);

See Application::make_pca9685_component().

API Reference

PCA9685OutputComponent

class PCA9685OutputComponent : public Component, public I2CDevice

PCA9685 float output component.

Public Functions

PCA9685OutputComponent(I2CComponent *parent, float frequency, uint8_t mode = PCA9685_MODE_OUTPUT_ONACK | PCA9685_MODE_OUTPUT_TOTEM_POLE)

Construct the component.

Parameters
  • frequency: The frequency of the PCA9685.
  • phase_balancer: How to balance phases.
  • mode: The output mode. For example, PCA9685_MODE_OUTPUT_ONACK or PCA9685_MODE_OUTPUT_TOTEM_POLE.

PCA9685OutputComponent::Channel *create_channel(uint8_t channel, PowerSupplyComponent *power_supply = nullptr, float max_power = 1.0f)

Get a PCA9685 output channel.

Return
The new channel output component.
Parameters
  • channel: The channel number.
  • power_supply: The power supply that should be set for this channel. Default: nullptr.
  • max_power: The maximum power output of this channel. Each value will be multiplied by this.

void set_frequency(float frequency)

Manually set the frequency of this PCA9685.

void set_mode(uint8_t mode)

Manually set the PCA9685 output mode, see constructor for more details.

float get_frequency() const
uint8_t get_mode() const
void setup()

Setup the PCA9685.

void dump_config()
float get_setup_priority() const

HARDWARE setup_priority.

void loop()

Send new values if they were updated.

Protected Functions

void set_channel_value(uint8_t channel, uint16_t value)

Protected Attributes

float frequency_
uint8_t mode_
uint8_t min_channel_
uint8_t max_channel_
uint16_t pwm_amounts_[16]
bool update_
class Channel : public output::FloatOutput

Public Functions

Channel(PCA9685OutputComponent *parent, uint8_t channel)
void write_state(float state)

Protected Attributes

PCA9685OutputComponent *parent_
uint8_t channel_