BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Controling a LED strip with virtual slider, buton and Menu

Greetings

I have looked around but I can’t seem to find anything about my problem, I am not that good in code so this may be really simple just that I can’t figure it out.

I have a project with an ESP8266 and an RGB light strip (just a normal LED strip no Neopixel magic) and I want to be able to select a color with the Menu widget and then click a button widget and then the LED strip changing to the “selected color”. that part I have seemed to figure out, what I can’t figure out is how to dim the LED strip with a slider widget.

it would be really helpful if someone could help

Thanks in advance

Dimming this type of LED strip is done by reducing the brightness of the three colours (Red, Green & Blue).

If 255, 255, 255 is full brightness then 128, 128, 128 is half brightness.

If your colour was 193, 88, 201 then 30% brightness would be 60, 26, 60

As you can see, 193 and 201 both come out at 60 when you rescale them, so colour rendition may drift slightly as you dim the strip.

Pete.

thanks!

ill get back with some code soon

I came up with some code but it doesn’t seem to work.
I read the value of the slider on V2
then I have preset colors in the cases for the R, G and B. but the brightness doesn’t change if I change the state if the slider.

the code

  int S;

BLYNK_WRITE(V2) 
{   
  S = param[0].asInt(); 

}

BLYNK_WRITE(V1) {
  switch (param.asInt())
  {
    case 1: // Red
      digitalWrite(4, 0);
      digitalWrite(0, 0);
      digitalWrite(2, 0);
      
      digitalWrite(4, 127.5);
      break;
      
    case 2: // Item 2
    
      digitalWrite(4, 0);
      digitalWrite(0, 0);
      digitalWrite(2, 0);
      
      digitalWrite(0, 255);
      break;
      
    case 3: // Item 3
      digitalWrite(4, 0);
      digitalWrite(0, 0);
      digitalWrite(2, 0);
      
      break;
      
    default:
      digitalWrite(4, 0);
      digitalWrite(0, 0);
      digitalWrite(2, 0);
  }
}

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);



  BLYNK_CONNECTED(); 
  {
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
      digitalWrite(4, LOW);
}
}
void loop()
{
  Blynk.run();

  
}

That’s because your slider doesn’t do anything.

This method is used to capture values from a widget that sends array of values. A slider doesn’t do this, so the correct method is this:

S = param.asInt();

However, you then have to do something with the S variable that you’ve used to capture/store the slider value, but your code doesn’t do this.

Pete.

Thanks for the fast answer

so if I want to get full red (255) and then be able to dim it I would need to use the following line?
digitalWrite(4, (255/S));
or wouldn’t this work?

my slider is set to go from 10 - 1

That looks like it might work for your red channel, but it’s not giving you any control over colour.

Pete.

it didn’t seem to work the brightness didn’t change

and my intent for it is to have different preset colours that I can choose from in the menu instead of using 3 different sliders for RGB, and then just change the brightness with a single slider

like if item 1 is white then I would use

digitalWrite(4, (255/S));
digitalWrite(0, (255/S));
digitalWrite(2, (255/S));

as that would give me white and then I would be able to have it on a smaller brightness.
but nothing happens when I use the slider.

I guess it depends where within your sketch you’ve pout these additional lines of code.

Also, your two widgets are working against each other, because you aren’t taking in to account the brightness value when writing the RGB values to the digital pins in BLYNK_WRITE(V1).

Pete.