(SOLVED) Arduino PCA9685 I²C-bus controller (Control with Widgets)

is there a way to use slider to control led brightness using PCA9685
I²C-bus controller ?

here is sample sketch

#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

void setup() {
  Serial.println("16 channel PWM test!");
  pwm.setPWMFreq(1600);  // This is the maximum PWM frequency


void loop() {

  pwm.setPWM(1, 0, 4096 );//setPWM(channel, on, off)


more info https://cdn-learn.adafruit.com/downloads/pdf/16-channel-pwm-servo-driver.pdf

Is this a single LED, or a strip of LEDs that you’re trying to control?
Is it just brightness, or RGB colour that you’re after?


5 x 150mA differen color LEDs for notification purposes. The reason I would like to use i2c is to avoid running 1wire for each led plus gnd wire.

Hi @Zbx,
I would start trying something simple like:

BLYNK_WRITE(V1) // slider using Virtual Pin V1 between 0 and 4096
brightness = param.asInt();
pwm.setPWM(1, 0, brightness);//setPWM(channel, on, off)

After glancing at the Adafruit page about this device, I would say that you can certainly use a combination of sliders and step widgets to make adjustment to all the variables needed.

This is not “working” code, but just an example:

BLYNK_WRITE(V0) // Step widget
  Chan = param.asInt();

BLYNK_WRITE(V1) // 1st slider widget
  PMWON = param.asInt();

BLYNK_WRITE(V2) // 2nd slider widget
  PMWOFF = param.asInt();

pwm.setPWM(Chan, PMWON, PMWOFF);  //setPWM(channel, on, off)

PS, I spend so much time editing, I missed seeing your post @psoro :slight_smile:

Lol, no worries… your code is more complete than mine, you are covering all arguments (channel, transition from low to high and transition from high to low) :slight_smile:

thanx psoro!
thanx Gunner!
i got both examples working .
now if only blynk would allow me to control virtual pins in Eventor settings

But that is exactly what Eventor does. If you are having Eventor issues, open up a new topic and supply details.

with your sample code it would be nice to add encoder like controller(with tiny led) to switch between channels and another one to control brightness

The step widget can also be set to act sorta like an encoder. Set Send Step to Yes and it will alternate between a positive and negative number (determined by Step value) as you toggle the back and forth buttons. You can then write some code to translate that back and forth count into your encoder application needs.

The value shown on the step widget is not correct when in Send Step mode… ( @Dmitriy - just a reminder: New Android Release 2.10.0 )… but you can setup a display widget to see the true value with this simple example.

BLYNK_WRITE(V0) // Step Widget
int StepState = param.asInt();
Blynk.virtualWrite(V1, StepState); // Display Widget

Controlling brightness can be done with a Slider or Step widget, as previously shown. Basicly you simply use Blynk widgets to supply the variable values you require for your controller code… how you write your code is up to you.


1 Like