Device::Chip::PCA9685 - A Device::Chip implementation for the PCA9685 chip
Device::Chip::PCA9685
Device::Chip
This class implements a Device::Chip interface for the PCA9685 chip, a 12-bit 16 channel PWM driver.
use Device::Chip::PCA9685; use Device::Chip::Adapter; my $adapter = Device::Chip::Adapter->new_from_description("LinuxKernel"); my $chip = Device::Chip::PCA9685->new(); # This is the i2c bus on an RPI 2 B+ $chip->mount($adapter, bus => '/dev/i2c-1')->get; $chip->enable()->get; $chip->set_frequency(400)->get; # 400 Hz $chip->set_channel_value(10, 1024)->get; # Set channel 10 to 25% (1024/4096) $chip->set_channel_full_value(10, 1024, 3192)->get; # Set channel 10 to ON at COUNTER=1024, and OFF at COUNTER=3192 (50% duty cycle, with 25% phase difference)
$chip->set_channel_value($channel, $time_on, $offset = 0)->get
Sets a channel PWM time based on a single value from 0-4095. Starts the channel to turn on at COUNTER = 0, and off at $time_on. $offset lets you stagger the time that the channel comes on and off. This lets you vary the times that channels go on and off to reduce noise effects and power supply issues from large loads all coming on at once.
$offset
$on_time := 0; $off_time := $time_on;
$on_time
$off_time
$chip->set_channel_full_value($channel, $on_time, $off_time)->get
Set a channel value, on and off time. Lets you control the full on and off time based on the 12 bit counter on the device.
$chip->set_channel_on($channel)->get
Set a channel to full on. No off time at all.
$chip->set_channel_off($channel)->get
Set a channel to full off. No on time at all.
$chip->set_default_mode()->get
Reset the default mode back to the PCA9685.
$chip->set_frequency()
Set the prescaler to the desired frequency for PWM. Returns the real frequency due to rounding.
$chip->enable()->get
Enable the device. Must be the first thing done with the device.
Ryan Voots, <simcop2387@simcop2387.info> Paul 'LeoNerd' Evans <leonerd@leonerd.org.uk>
To install Device::Chip::PCA9685, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Chip::PCA9685
CPAN shell
perl -MCPAN -e shell install Device::Chip::PCA9685
For more information on module installation, please visit the detailed CPAN module installation guide.