How can i fade LEDs concurrently and at different rates on a PCA9685 chain ?

this is my first coding project, so please let me know if anything needs further clarification.

this is the desired outcome of the program i am trying to write:

  1. all LEDs turn on at the same time. start of cycle.
  2. all LEDs start to fade out concurrently, at various speeds. for example:
    a) led 2 on pca1 fades out, off at 2000ms.
    b) led 9 on pca2 fades out, off at 9000ms.
    c) led 15 on pca3 fades out, off at 15000ms.
  3. led 15 on pca3 has the longest fade cycle, so now all LEDs are off at 15000ms, completing the end of the cycle.
  4. pause for 5000ms. then loop.

i've read through through several posts/guides, which addressed fading LEDs concurrently on an Arduino's built-in PWM pins, as well as fading LEDs sequentially on a PCA9685, but not concurrent fading on a PCA9685. but i cannot figure out how to bring these elements together in order to create the sequence that i described above.

i'd greatly appreciate any help at all with this. if you happen to know how i might be able to achieve this with CircuitPython, that would also be very much appreciated. thank you so much for your time.

You just set the desired pwm through I2C at the right time (use a library)
Of course you can’t write blocking code.

For extra information and examples look at

1 Like

From the data sheet the outputs can be controlled individually. If you can't find a library that handles this you will have to figure out the commands from the data sheet.

7.3.3 LED output and PWM control
The turn-on time of each LED driver output and the duty cycle of PWM can be controlled
independently using the LEDn_ON and LEDn_OFF registers.
There will be two 12-bit registers per LED output. These registers will be programmed by
the user. Both registers will hold a value from 0 to 4095. One 12-bit register will hold a
value for the ON time and the other 12-bit register will hold the value for the OFF time. The
ON and OFF times are compared with the value of a 12-bit counter that will be running
continuously from 0000h to 0FFFh (0 to 4095 decimal).

1 Like

Post the code you have used to test that the hardware works at all, and that you can control the 48 PWM pins in any way.

Adafruit has one with a convenient setPwm() function

Why do new members only use words? Leds here, pins there, ports....
Draw a logic diagram showing what the intention is.
Google ought to be well known. Google on " Arduino + PCA9685" will likely give at lot.

1 Like

I have merged your cross-posts @noodley.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

in the end driving a LED on a PC9685 isn't so much different to a analogWrite of a discrete LED.

Check my LED Toolkit. It can handle LEDs on discrete Arduino pins and on a PCA9685 very similar.
https://werner.rothschopf.net/microcontroller/202202_tools_led_en.htm

start with the example 0515_smooth_led (for PCA9685).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.