[Solved] Slider + Button Help

I’m trying to make a slider and a button for dimming:

The slider is the dimmer %, from 0 to 100.

The button is dual state button, if it’s ON then my code will call a function and dimmer slider will not work, if It’s OFF then dimmer slider will work.

The problem is: The button andslider are working, but when I change the value of slider, it changes my button value!!

Here’s my code:

#include <UIPEthernet.h>
#include <BlynkSimpleUIPEthernet.h>
char auth[] = "My auth code";

void setup() {
Serial.begin(9600);
Blynk.begin(auth); // (BLYNK)

int autodimmer; // (BLYNK) Auto Dimmer Button

void loop()
{
  Blynk.run(); // (BLYNK) Run
}

void DimmerFunction()
{
  if (autodimmer >= 1)
  {
    // Code
  }
  else  
  {
  // Do nothing
  }
}

BLYNK_WRITE(V18)  // (BLYNK) Botão Auto Dimmer
{
  autodimmer = param.asInt();
  if (autodimmer == 1) // If Auto dimmer is ON then calls function Dimmer()
  {
    DimmerFunction(); 
  }
}

BLYNK_WRITE(V5)  // (BLYNK) Slider Dimmer
{
  dimmer = param.asInt(); // dimmer = Value got from dimmer Slider
  if (autodimmer == 0) // If auto dimmer is OFF then set the dimmer according slider value
  {
    Set.dimmer(dimmer);
  }
  // If AutoDimmer button is true, then do nothing
}

@hbadotti do you have the button correctly set to SWITCH rather than PUSH mode?

From the code you have provided I don’t see how the slider can change the button value.

Yes, I do… Probably is an issue with Blynk… When I print value of dimmer and autodimmer, the autodimmer prints “0” or “1” for sometime then start printing “24946”… When I slide the dimmer, it changes the another pin (Autodimmer) value!

@Costas

— Edit:

I added
Serial.println(autodimmer);
Serial.println(dimmer)
in “BLYNK_WRITE(V5) // SLIDER”

Then I got this…

24946 // AUTODIMMER STARTS WITH 24946
2 // DIMING = 2
24946 // AUTO DIMMER
0 // DIMING = 1…
24946
1
24946
14
24946
23
24946
30
24946
34
24946
39
24946
43
24946
47
24946
52
24946
57
24946
65
24946
72
24946
79
24946
87
24946
90
24946
1 // THEN I PRESS AUTO DIMMER BUTTON, IT GOES TO 1
87 // CHANGING DIMMING AND EVERYTHING IS OK…
1
74
1
66
1
60
1
53
1
47
1
43
1
39
1
34
1
31
1
25
1
19
1
15
1
13
1
9
1
6
1
4
1
1
1
0
1
2
24946 // WHEN THE SLIDER CHANGE ITS DIRECTION, IT CHANGES AUTODIMMER BUTTON TO 24946…
23
24946
34
24946
40
24946
48
24946
54
24946
56
24946
59
24946
62
24946

Almost always a Blynker problem, not a Blynk problem.
If you are going to provide a cut down version of your sketch please ensure it compiles.
You have numerous errors in your sketch.

Here is an ESP version of your sketch with the corrections and Blynk performs as expected.
Serial Monitor:

Project started
0
80
Set.dimmer(dimmer)
0
20
Set.dimmer(dimmer)
autodimmer >= 1
1
78
1
18
0
80
Set.dimmer(dimmer)
// Dimmer.ino 30 Mar 2017 http://community.blynk.cc/t/slider-button-help/12993
//#include <UIPEthernet.h>
//#include <BlynkSimpleUIPEthernet.h>

#include <ESP8266WiFi.h>            //https://github.com/esp8266/Arduino
#include <BlynkSimpleEsp8266.h>     // for TCP connection
char auth[] = "xxxx";
char ssid[] = "xxxx";
char pass[] = "xxxx";

void setup() {
  //Serial.begin(9600);
  Serial.begin(115200);
  Serial.println();
  Serial.println("Project started");
  Blynk.begin(auth, ssid, pass, "xxxx"); // (BLYNK)
}

int autodimmer; // (BLYNK) Auto Dimmer Button
int dimmer; 

void loop()
{
  Blynk.run(); // (BLYNK) Run
}

void DimmerFunction()
{
  if (autodimmer >= 1)
  {
    // Code
    Serial.println("autodimmer >= 1");
  }
  else  
  {
    // Do nothing
  }
}

BLYNK_WRITE(V18)  // (BLYNK) Botão Auto Dimmer
{
  autodimmer = param.asInt();
  if (autodimmer == 1) // If Auto dimmer is ON then calls function Dimmer()
  {
    DimmerFunction(); 
  }
}

BLYNK_WRITE(V5)  // (BLYNK) Slider Dimmer
{
  dimmer = param.asInt(); // dimmer = Value got from dimmer Slider
  Serial.println(autodimmer);
  Serial.println(dimmer);
  if (autodimmer == 0) // If auto dimmer is OFF then set the dimmer according slider value
  {
    Serial.println("Set.dimmer(dimmer)");
    //Set.dimmer(dimmer);
  }
  // If AutoDimmer button is true, then do nothing
}

Ensure you don’t have the mapping connected in the slider configuration.
Change the sketch above back to Ethernet mode and confirm it works ok.

I’m sorry, I love Blynk, it’s the best app ever made…

Sorry but what you meant with “Ensure you don’t have the mapping connected in the slider configuration.”… My english is not good at all…

Ok, I still got the same problem… When you slided it? Did you slided for some time? Because when I press Autodimmer button, it works for some slidings then it changes to “24946”…

Mapping - in the slider settings there is a “wire” between 0 and 100 range. If you have accidentally clicked the wire when you were setting the range from 0 to 100 the “wire” will have an additional circular symbol around the wire. Ensure additional circular symbol is not shown (mapping disabled).

How long is “some time”?

Got it! The wire (mapping) was already disable…

Some time = About 1 seconds sliding up and down

Are you using the newer vertical slider or the original horizontal slider as I notice you say up and down rather than left and right?

The new (vertical) slider did have some recent bugs and I don’t currently use it, even though I asked Blynk to add the vertical slider widget.

The default is for sliders to be set as SEND ON RELEASE as ON. Is your slider set as ON or OFF for this setting? It must be set as ON.

I used both (vertical and horizontal slider) and tried with both ways send on release on and off. Will change back to Vertical and send on release on (which’s already ON)

Try horizontal as that is what is working for me.

If horizontal and ON is still buggy for you, post your basic sketch, not the full sketch, that is failing.

I do have Ethernet access I can try but it’s not something I use very often.

Ok

// ===================================================== DIMMER INICIO =====================================================
int autodimmer; // (BLYNK) Auto Dimmer
int dimmer; // (BLYNK) Dimmer 

void Dimmer()
{
  if (autodimmer >= 1)
  {
    if ((hour() >= 7) && (hour() <= 19))
    {
      myNextion.sendCommand("dim=100");
    }
    else if ((hour() > 19) && (hour() <= 23))
    {
      myNextion.sendCommand("dim=50");
    }
    else
    {
      myNextion.sendCommand("dim=10");
    }
  }
}

BLYNK_WRITE(V18)  // (BLYNK) Botão Auto Dimmer
{
  autodimmer = param.asInt();
  Serial.println(autodimmer);
  if (autodimmer == 1)
  {
    Dimmer();
  }
}

BLYNK_WRITE(V22)  // (BLYNK) Slider Dimmer
{
  dimmer = param.asInt();
  Serial.println(autodimmer);
  Serial.println(dimmer);
  if (autodimmer == 0) // If auto dimmer is OFF then set the dimmer according slider value
  {
    Serial.println(dimmer);
    String setardimmer = "dim=" + String(int(param.asInt()));
    myNextion.sendCommand(setardimmer.c_str());
  }
}
// ===================================================== DIMMER FIM =====================================================

No, what I want to see is my full working ESP sketch converted back to Ethernet and failing for you.

Your code adapted worked!!! Whyy???

#include <UIPEthernet.h> // (BLYNK) ETHERNET
#include <BlynkSimpleUIPEthernet.h> // (BLYNK)
char auth[] = "myauth"; // (BLYNK) Código Token
bool isFirstConnect = true; // (BLYNK)

void setup() {
  Serial.begin(9600);
  //Serial.begin(115200);
  Serial.println();
  Serial.println("Project started");
  Blynk.begin(auth); // (BLYNK)
}

int autodimmer; // (BLYNK) Auto Dimmer Button
int dimmer; 

void loop()
{
  Blynk.run(); // (BLYNK) Run
}

void DimmerFunction()
{
  if (autodimmer >= 1)
  {
    // Code
    Serial.println("autodimmer >= 1");
  }
  else  
  {
    // Do nothing
  }
}

BLYNK_WRITE(V18)  // (BLYNK) Botão Auto Dimmer
{
  autodimmer = param.asInt();
  if (autodimmer == 1) // If Auto dimmer is ON then calls function Dimmer()
  {
    DimmerFunction(); 
  }
}

BLYNK_WRITE(V5)  // (BLYNK) Slider Dimmer
{
  dimmer = param.asInt(); // dimmer = Value got from dimmer Slider
  Serial.println(autodimmer);
  Serial.println(dimmer);
  if (autodimmer == 0) // If auto dimmer is OFF then set the dimmer according slider value
  {
    Serial.println("Set.dimmer(dimmer)");
    //Set.dimmer(dimmer);
  }
  // If AutoDimmer button is true, then do nothing
}

Dunno, other than it suggests you have more bugs in your full sketch.

Add a bit, then test until you find the bugs.

Thanks a lot for the support and patience! I’ll study this issue later. You can mark this topic as solved.