16-channel, 12-bit PWM Fm I2C-bus LED controller
PCA9685 Class Reference
Example: More...
#include <PCA9685.h>
Detailed Description
Example:
include "mbed.h" include "PCA9685.h"
PCA9685 myPWMSensor ( I2C_SDA, I2C_SCL, PCA9685::PCA9685_ADDRESS_0, 400000 );
Ticker newPWMOutput; DigitalOut myled(LED1);
PCA9685::PCA9685_status_t aux; uint8_t myState = 0;
void changeDATA ( void ) { myState++; }
int main() { Reset the device aux = myPWMSensor.PCA9685_SoftReset (); wait_us ( 5 );
Configure the PWM frequency and wake up the device aux = myPWMSensor.PCA9685_SetPWM_Freq ( 1000 ); // PWM frequency: 1kHz aux = myPWMSensor.PCA9685_SetMode ( PCA9685::MODE1_SLEEP_DISABLED );
newPWMOutput.attach( &changeDATA, 1 ); // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
Let the callbacks take care of everything while(1) { sleep();
myled = 1;
switch ( myState ) { default: case 0: All LEDs: Delay Time = 1% | PWM duty cycle = 99% aux = myPWMSensor.PCA9685_SetPWM_DutyCycle_AllLEDs ( 0, 99 );
myState = 1; break;
case 1: All LEDs: Delay Time = 100% | PWM duty cycle = 1% aux = myPWMSensor.PCA9685_SetPWM_DutyCycle_AllLEDs ( 100, 1 );
myState = 2; break;
case 2: LED1: Delay Time = 10% | PWM duty cycle = 30% aux = myPWMSensor.PCA9685_SetPWM_DutyCycle ( PCA9685::PCA9685_LED1, 10, 30 );
myState = 0; break; }
myled = 0; } }
Library for the PCA9685 16-channel, 12-bit PWM Fm+ I2C-bus LED controller.
Definition at line 96 of file PCA9685.h.
Member Enumeration Documentation
enum PCA9685_address_t |
DEFAULT ADDRESSES.
NOTE: There are a maximum of 64 possible programmable addresses using the 6 hardware address pins. Two of these addresses, Software Reset and LED All Call, cannot be used because their default power-up state is ON, leaving a maximum of 62 addresses. Using other reserved addresses, as well as any other subcall address, will reduce the total number of possible addresses even further.
To access to a certain address just use the following method: PCA9685_ADDRESS_0 + Counter_Address Ex: PCA9685_ADDRESS_0 + 1 = 0x40 + 1 = 0x41 ( 0b1000001 ) PCA9685_ADDRESS_0 + 10 = 0x40 + 10 = 0x4A ( 0b1001010 ) and so on...
- Enumerator:
enum PCA9685_mode1_ai_t |
enum PCA9685_mode1_sub1_t |
enum PCA9685_mode1_sub2_t |
enum PCA9685_mode1_sub3_t |
enum PCA9685_mode2_och_t |
OUTNE.
- Enumerator:
enum PCA9685_registers_t |
REGISTER DEFINITIONS.
- Enumerator:
enum PCA9685_status_t |
SUBADDRESS.
NOTE: At power-up, Sub Call I2C-bus addresses are disabled. PCA9685 does not send an ACK when E2h (R/W = 0) or E3h (R/W = 1), E4h (R/W = 0) or E5h (R/W = 1), or E8h (R/W = 0) or E9h (R/W = 1) is sent by the master.
Constructor & Destructor Documentation
PCA9685 | ( | PinName | sda, |
PinName | scl, | ||
uint32_t | addr, | ||
uint32_t | freq | ||
) |
Create an PCA9685 object connected to the specified I2C pins.
- Parameters:
-
sda I2C data pin scl I2C clock pin addr I2C slave address freq I2C frequency in Hz.
16-channel, 12-bit PWM Fm+ I2C-bus LED controller. Functions file.
- Returns:
- NA
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- NaN.
- Warning:
- NaN
- Precondition:
- This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).
Definition at line 20 of file PCA9685.cpp.
~PCA9685 | ( | ) |
Delete PCA9685 object.
Definition at line 28 of file PCA9685.cpp.
Member Function Documentation
PCA9685::PCA9685_status_t PCA9685_SetALLCALL | ( | PCA9685_mode1_allcall_t | myALLCALL_mode ) |
It sets ALLCALL mode.
PCA9685_SetALLCALL ( PCA9685_mode1_allcall_t )
The device responds ( Enabled ) or not ( Disabled ) to LED All Call I2C-bus address.
- Parameters:
-
[in] myALLCALL_mode,: ALLCALL Enabled/Disabled. [out] NaN.
- Returns:
- Status of PCA9685_SetALLCALL.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- NaN.
- Warning:
- NaN.
Definition at line 796 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetAllLED_OFF | ( | void | ) |
It sets All LEDs OFF.
PCA9685_SetAllLED_OFF ( void )
It sets All LEDs OFF.
- Parameters:
-
[in] NaN. [out] NaN.
- Returns:
- Status of PCA9685_SetAllLED_OFF.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- Update on ACK requires all 4 PWM channel registers to be loaded before outputs will change on the last ACK.
- Warning:
- NaN.
Definition at line 596 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetAllLED_ON | ( | void | ) |
It sets All LEDs ON.
PCA9685_SetAllLED_ON ( void )
It sets All LEDs ON.
- Parameters:
-
[in] NaN. [out] NaN.
- Returns:
- Status of PCA9685_SetAllLED_ON.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- Update on ACK requires all 4 PWM channel registers to be loaded before outputs will change on the last ACK.
- Warning:
- NaN.
Definition at line 530 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetINVERT | ( | PCA9685_mode2_invrt_t | myINVERT_mode ) |
It sets INVERT mode.
PCA9685_SetINVERT ( PCA9685_mode2_invrt_t )
Output logic state inverted ( Enabled ) or not ( Disabled ). Value to use when external driver used. Applicable when OE = 0
- Parameters:
-
[in] myINVERT_mode,: INVERT Enabled/Disabled. [out] NaN.
- Returns:
- Status of PCA9685_SetINVERT.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- NaN.
- Warning:
- NaN.
Definition at line 842 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetLED_OFF | ( | PCA9685_led_channel_t | myLEDchannel ) |
It sets the LEDn OFF.
PCA9685_SetLED_OFF ( PCA9685_led_channel_t )
It sets LEDn OFF.
- Parameters:
-
[in] myLEDchannel,: Chosen LED ( channel ). [out] NaN.
- Returns:
- Status of PCA9685_SetLED_OFF.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- Update on ACK requires all 4 PWM channel registers to be loaded before outputs will change on the last ACK.
- Warning:
- NaN.
Definition at line 464 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetLED_ON | ( | PCA9685_led_channel_t | myLEDchannel ) |
It sets the LEDn ON.
PCA9685_SetLED_ON ( PCA9685_led_channel_t )
It sets LEDn ON.
- Parameters:
-
[in] myLEDchannel,: Chosen LED ( channel ). [out] NaN.
- Returns:
- Status of PCA9685_SetLED_ON.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- Update on ACK requires all 4 PWM channel registers to be loaded before outputs will change on the last ACK.
- Warning:
- NaN.
Definition at line 398 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetMode | ( | PCA9685_mode1_sleep_t | myMode ) |
It configures the mode of the device: Sleep or Normal operation mode.
PCA9685_SetMode ( PCA9685_mode1_sleep_t )
It configures the device in Low power mode or in Normal operation mode.
- Parameters:
-
[in] myMode,: Sleep or Normal mode. [out] NaN.
- Returns:
- Status of PCA9685_SetMode.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- NaN.
- Warning:
- NaN.
Definition at line 94 of file PCA9685.cpp.
PCA9685_status_t PCA9685_SetOCH | ( | PCA9685_mode2_och_t | myOCH_mode ) |
It sets OCH mode.
PCA9685::PCA9685_status_t PCA9685_SetOUTDRV | ( | PCA9685_mode2_outdrv_t | myOUTDRV_mode ) |
It sets OUTDRV mode.
PCA9685_SetOUTDRV ( PCA9685_mode2_outdrv_t )
It sets the 16 LEDn as open-drain or totem pole structure.
- Parameters:
-
[in] myOUTDRV_mode,: OUTDRV mode. [out] NaN.
- Returns:
- Status of PCA9685_SetOUTDRV.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- NaN.
- Warning:
- NaN.
Definition at line 887 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetPWM_DutyCycle | ( | PCA9685_led_channel_t | myLEDchannel, |
uint8_t | myDelay, | ||
uint8_t | myPWM_DutyCycle | ||
) |
It configures a new PWM duty cycle on a given LED.
PCA9685_SetPWM_DutyCycle ( PCA9685_led_channel_t , uint8_t , uint8_t )
It sets a new PWM duty cycle on the given LED ( channel ).
- Parameters:
-
[in] myLEDchannel,: Chosen LED ( channel ). [in] myDelay,: PWM delay. [in] myPWM_DutyCycle,: PWM duty cycle. [out] NaN.
- Returns:
- Status of PCA9685_SetPWM_DutyCycle.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- Datasheet p.17 ( Example 1 and Example 2).
- Warning:
- NaN.
Definition at line 207 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetPWM_DutyCycle_AllLEDs | ( | uint8_t | myDelay, |
uint8_t | myPWM_DutyCycle | ||
) |
It configures a new PWM duty cycle on all LEDs.
PCA9685_SetPWM_DutyCycle_AllLEDs ( uint8_t , uint8_t )
It sets a new PWM duty cycle on all LEDs ( all channels ).
- Parameters:
-
[in] myDelay,: PWM delay. [in] myPWM_DutyCycle,: PWM duty cycle. [out] NaN.
- Returns:
- Status of PCA9685_SetPWM_DutyCycle_AllLEDs.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- Datasheet p.17 ( Example 1 and Example 2).
- Warning:
- NaN.
Definition at line 303 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetPWM_Freq | ( | float | myNewFrequency ) |
It configures a new PWM frequency.
PCA9685_SetPWM_Freq ( float )
It sets a new PWM frequency.
- Parameters:
-
[in] myNewFrequency,: New PWM frequency. [out] NaN.
- Returns:
- Status of PCA9685_SetPWM_Freq.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- This library can ONLY work with the internal clock, otherwise PCA9685_INTERNAL_CLOCK must be changed in the header file.
- Warning:
- NaN.
Definition at line 139 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetSUB1 | ( | PCA9685_mode1_sub1_t | mySUB1_mode ) |
It sets SUB1 mode.
PCA9685_SetSUB1 ( PCA9685_mode1_sub1_t )
The device responds ( Enabled ) or not ( Disabled ) to I2C-bus subaddress 1.
- Parameters:
-
[in] mySUB1_mode,: SUB1 Enabled/Disabled. [out] NaN.
- Returns:
- Status of PCA9685_SetSUB1.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- NaN.
- Warning:
- NaN.
Definition at line 661 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetSUB2 | ( | PCA9685_mode1_sub2_t | mySUB2_mode ) |
It sets SUB2 mode.
PCA9685_SetSUB2 ( PCA9685_mode1_sub2_t )
The device responds ( Enabled ) or not ( Disabled ) to I2C-bus subaddress 2.
- Parameters:
-
[in] mySUB2_mode,: SUB2 Enabled/Disabled. [out] NaN.
- Returns:
- Status of PCA9685_SetSUB2.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- NaN.
- Warning:
- NaN.
Definition at line 706 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SetSUB3 | ( | PCA9685_mode1_sub3_t | mySUB3_mode ) |
It sets SUB3 mode.
PCA9685_SetSUB3 ( PCA9685_mode1_sub3_t )
The device responds ( Enabled ) or not ( Disabled ) to I2C-bus subaddress 3.
- Parameters:
-
[in] mySUB3_mode,: SUB3 Enabled/Disabled. [out] NaN.
- Returns:
- Status of PCA9685_SetSUB3.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- NaN.
- Warning:
- NaN.
Definition at line 751 of file PCA9685.cpp.
PCA9685::PCA9685_status_t PCA9685_SoftReset | ( | void | ) |
It resets the device by software.
PCA9685_SoftReset ( void )
It performs a software reset.
- Parameters:
-
[in] NaN. [out] NaN.
- Returns:
- Status of PCA9685_SoftReset.
- Date:
- 7/November/2017
- Version:
- 7/November/2017 The ORIGIN
- Precondition:
- The device will be ready to be addressed again within the specified bus free time ( t_BUF ).
- Warning:
- NaN.
Definition at line 54 of file PCA9685.cpp.
Generated on Sun Jul 17 2022 17:06:29 by 1.7.2