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

Update Slider Value


#1

Hallo,

hope someone can help :slight_smile:

First of all - what I want to do:

Blynk: 2 Buttons (Switch Mode) + 1 Slider (0-255)

I got a Blue Button, that turns on or off the Blue leds and a Red Button that turns on or off the Red Leds.
If the the Blue one is on, the Red is off otherwise.

with the Slider I only want to controll the Brightnes of the Led Strip, but I can´t sync the Slider with the Virtual Pins.

V40 = Slider
V1 = Blue
V2 = Red
V10 = Display Widget

> #include <FastLED.h>
> #include <ESP8266WiFi.h>
> #include <BlynkSimpleEsp8266.h>
> 
> #define BLYNK_PRINT Serial
> #define NUM_LEDS 12
> #define DATA_PIN 4
> #define CLOCK_PIN 13
> 
> CRGB leds[NUM_LEDS];
> 
> char auth[] = "744d992b36c94c448e86xxxxxx";
> char ssid[] = "xxxx";
> char pass[] = "xxxxxx";
> char server[] = "xxx.xxx.xxx.xx";
> 
> int ledBrightnes = 164;
> 
> void setup()
> {
>   Serial.begin(9600);
>   Blynk.begin(auth, ssid, pass, server);
>   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
> }
> 
> BLYNK_WRITE(V40)
> {
>   int pinValue = param.asInt();
>   ledBrightnes = pinValue;
>   Serial.println(ledBrightnes);
> }
> 
> 
> BLYNK_WRITE(V1)
> {
>   int pinValue = param.asInt();
>   Serial.println(pinValue);
> 
>   if (pinValue == 1)
>   {
>     fill_gradient(leds,0,CHSV(10,255,ledBrightnes),11,CHSV(30,255,ledBrightnes),SHORTEST_HUES); 
>     Blynk.virtualWrite(V2, 0);
>     Blynk.virtualWrite(V10, "Rot an");
>     Blynk.virtualWrite(V11, ledBrightnes);
>     FastLED.show();  
>   }
> 
>   if (pinValue == 0)
>   {
>     fill_gradient(leds,0,CHSV(90,255,0),11,CHSV(120,255,0),SHORTEST_HUES); 
>     FastLED.show();
>     Blynk.virtualWrite(V2, 0);
>     Blynk.virtualWrite(V10, "Lichter aus");
>   }
> }
> 
> BLYNK_WRITE(V2)
> {
>   int pinValue = param.asInt();
>   Serial.println(pinValue);
> 
>   if (pinValue == 1)
>   {
>     fill_gradient(leds,0,CHSV(110,255,255),11,CHSV(130,255,255),SHORTEST_HUES); 
>     FastLED.show();
>     Blynk.virtualWrite(V1, 0);
>     Blynk.virtualWrite(V10, "Blau an");
>   }
> 
>   if (pinValue == 0)
>   {
>     fill_gradient(leds,0,CHSV(90,255,0),11,CHSV(120,255,0),SHORTEST_HUES); 
>     FastLED.show();
>     Blynk.virtualWrite(V1, 0);
>     Blynk.virtualWrite(V10, "Lichter aus");
>   }
>   
> }
> 
> void loop()
> {
>   Blynk.run();
> }

#2

You may ned to add a Blynk.syncVirtual(V1); and a Blynk.syncVirtual(V2); to the end of your BLYNK_WRITE(V40)

I suspect that if you change the slider (brightness), then turn the red or blue led off then on it will be at the expected brightness.

You are changing the value of brightness, but need to re-run the V1 or V2 to change the value in the led program.


#3

You may also be able to just use FastLED.setBrightness(ledBrightnes); , although I am not too familiar with the FastLED library.

BLYNK_WRITE(V40)
 {
   int pinValue = param.asInt();
  ledBrightnes = pinValue;
   Serial.println(ledBrightnes);
   FastLED.setBrightness(ledBrightnes);
   FastLED.show();
 }

#4

You´re right Toro, the led and the blynk widget button turn off by changing the slider value.
Any ideas?


#5

No one any further idea to solve the problem?


#6

Have you tried the suggestion above? You may want to ask the FastLED library guys for some help.


#7

Hi,

have tried, but if I change the value of the slider I have to turn off and on the led to update the state.
The problem should not have any to do with the FastLED libary, more than the update of the slider.

The project should be very simple.

If one color is on, the other is off and the slider should only handle the brightness (without turning off and on the leds)


#8

The problem is in your code and how you are using the FastLED library commands, nothing Blynk specific.

Normally that library expects you to call FastLED.show() every time something changes… So you MUST run that command after changing the brightness as well… or run a fast timer to do it all the time (although I think adding just that command itself in void loop() should be OK?)


#9

did you try my suggestions?

OR


#10

ahaaaa… THX Toro and Gunner.

the FastLED.show(); in the slider (V40) was the solution … but…

If I set the slider e.g. to 255 and then turn on the red led all leds runs at 100% and I can change the brightness (physical) from 0 - 100%

If I set the slider e.g. to 127 and then turn on the led runs at 50% but then I only can slide from 0 - 50% physical brighness (serial monitor says 255)

Blynk.syncVirtual in V40 turns off the led if slider change.


#11

Sounds like improper use of the library commands, as the ledBrightness value is being changed (as shown in your serial monitor). Did you also add FastLED.setBrightness(ledBrightnes); to the BLYNK_WRITE(V40) ? Show the updated code that gives you the results you described. As mentioned, I do not have too much experience with the FastLED Library, but will do my best to assist.


#12

that is the code - but same problem.

If I turn on the red led at 255 and slide down to e.g. 100 - all is fine.
if I change to blue its about half of the brightness - if I slide up blue, serial monitor says 255 but the brightness isn´t 255. Then I turn off and on the blue - it is all fine and I can slide through all brightness values.

int ledBrightnes = 255;


BLYNK_WRITE(V40)
 {
   int pinValue = param.asInt();
   ledBrightnes = pinValue;
   FastLED.setBrightness(ledBrightnes);
   Serial.println(ledBrightnes);
   FastLED.show();
 }

#13
BLYNK_WRITE(V2)
> {
>   int pinValue = param.asInt();
>   Serial.println(pinValue);
> 
>   if (pinValue == 1)
>   {
>     fill_gradient(leds,0,CHSV(110,255,255),11,CHSV(130,255,255),SHORTEST_HUES); 
>     FastLED.show();
>     Blynk.virtualWrite(V1, 0);
>     Blynk.virtualWrite(V10, "Blau an");
>   }
> 
>   if (pinValue == 0)
>   {
>     fill_gradient(leds,0,CHSV(90,255,0),11,CHSV(120,255,0),SHORTEST_HUES); 
>     FastLED.show();
>     Blynk.virtualWrite(V1, 0);
>     Blynk.virtualWrite(V10, "Lichter aus");
>   }
>   
> }

I do not see ledBrightness in this function, as there is in the BLYNK_WRITE(V1). Maybe that could be the problem?


#14

As the ledBrightnes value is being updated (as shown in serial monitor). This is probably an issue with the way the FastLED library, and its commands, are being used; and not so much a problem with BLYNK.

I would look into the FastLED library commands, and try to get a better understanding of how they work/function. This may shine some light on what the issue may be.


#15

Here is the complete code (without defines,…)
I have set the ledBrightnes

int ledBrightnes = 255;


 void setup()
 {
   Serial.begin(9600);
   Blynk.begin(auth, ssid, pass, server);
   FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
 }
 
BLYNK_WRITE(V40)
 {
   int pinValue = param.asInt();
   ledBrightnes = pinValue;
   FastLED.setBrightness(ledBrightnes);
   Serial.println(ledBrightnes);
   Blynk.virtualWrite(V11, ledBrightnes);
   FastLED.show();
 }
 
 
 BLYNK_WRITE(V1)
 {
   int pinValue = param.asInt();
   Serial.println(pinValue);
 
   if (pinValue == 1)
   {
     fill_gradient(leds,0,CHSV(10,255,ledBrightnes),11,CHSV(30,255,ledBrightnes),SHORTEST_HUES); 
     Blynk.virtualWrite(V2, 0);
     Blynk.virtualWrite(V10, "Rot an");
     Blynk.virtualWrite(V11, ledBrightnes);
     FastLED.show();  
   }
 
   if (pinValue == 0)
   {
     fill_gradient(leds,0,CHSV(90,255,0),11,CHSV(120,255,0),SHORTEST_HUES); 
     Blynk.virtualWrite(V2, 0);
     Blynk.virtualWrite(V10, "Lichter aus");
     Blynk.virtualWrite(V11, ledBrightnes);
     FastLED.show();
   }
 }
 
 BLYNK_WRITE(V2)
 {
   int pinValue = param.asInt();
   Serial.println(pinValue);
 
   if (pinValue == 1)
   {
     fill_gradient(leds,0,CHSV(110,255,ledBrightnes),11,CHSV(130,255,ledBrightnes),SHORTEST_HUES);
     Blynk.virtualWrite(V1, 0);
     Blynk.virtualWrite(V10, "Blau an");
     Blynk.virtualWrite(V11, ledBrightnes);
     FastLED.show(); 
   }
 
   if (pinValue == 0)
   {
     fill_gradient(leds,0,CHSV(90,255,0),11,CHSV(120,255,0),SHORTEST_HUES);
     Blynk.virtualWrite(V1, 0);
     Blynk.virtualWrite(V10, "Lichter aus");
     Blynk.virtualWrite(V11, ledBrightnes);
     FastLED.show(); 
   }
   
 }
 
 void loop()
 {
   Blynk.run();
 }

#16

Proper way to format posted code in this forum… I fixed your post.

Blynk%20-%20FTFC


#17

So is it working as expected? Or are you still having problems?


#18

No … with this code is still the problem.

I can change the brightness for red or blue - but if I switch from one color to the other the brightness is lower then the value befor.

so if I turn on Red at 255 I can slide from 0 - 255 - than I change to blue an I can also change slider from 0 - 255 … all works fine.

if I change red to e.g. 150 an switch to blue, the slider and serial monitor gives correct values, and if I slide up to 255 it isn´t the maximum brightness. If I turn off and on … the correct brightness shows up on the leds.

I looks like

Slider value = 0 - 255 / Brightness = 0% - 100%

after switch the color:
Slidet value = 0 - 255 / Brightness = 0% - 50%


#19

OK, as mentioned above it sounds like an issue with how the FastLED library and its commands are being used.

I would check the FastLED library documentation.