Can´t change the timer interval

Can someone tell me, why I can´t change the timer interval from the timer, which calls Func_Mode_4 ??? :smiley:
The other loops should be called every 100ms, I only want to be able to adjust the interval to call void Func_Mode_4(){} with a slider widget on V26.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";

int timerBlinker = 1;
int varBlinker = 0;
int BlinkValue = 0;

BlynkTimer timer;
WidgetLCD lcd (V101);                                   //LCD Widget attached to Pin V101
WidgetLED led (V100);                                   //LED Widget attached to Pin V100

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode (LedPinD1, OUTPUT);
  timer.setInterval(100L, Func_Mode_1);                 //LED-Switch
  timer.setInterval(100L, Func_Mode_2);                 //LED-Dimmer
  timer.setInterval(100L, Func_Mode_3);                 //LED-Szene
  timerBlinker = timer.setInterval(100L, Func_Mode_4);   //LED-Blinker
}

void loop()
{
  Blynk.run();
  timer.run();
}


BLYNK_WRITE(V26)                                                         //Slider BlinkValue
{
  BlinkValue = param.asInt();
  timer.deleteTimer(timerBlinker);
  timerBlinker = timer.setInterval(BlinkValue*1000L, Func_Mode_4);
}

void Func_Mode_1() {
}

void Func_Mode_2() {
}

void Func_Mode_3() {
}

void Func_Mode_4() {
}

The problem is, that the interval from the loop Func_Mode_4 remains usually the same, also if I adjust the slider

I think you have to delete first and to re-create with the new timing

Which should look like?? :face_with_raised_eyebrow:
Can´t follow what you mean :see_no_evil:

See here:
https://playground.arduino.cc/Code/SimpleTimer

In case of problems let me know

P.S. SimpleTimer is the base for BlynkTimer !

Sorry but it doesn´t help me really on. Can´t understand why it doesn´t works because the following sketch works fine. But there I call only one loop. There I am able to adjust the interval :expressionless:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
WidgetLED led (V100);

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
char pass[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

int timerBlinker = 1;
int varBlinker = 0;
int BlinkValue = 0;
int OutputValue = 0;
int LedPinD1 = D1;

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode (LedPinD1, OUTPUT);
  timerBlinker = timer.setInterval(100, Func_Mode_4);
}

void loop()
{
  Blynk.run();
  timer.run();
}

BLYNK_WRITE(V26) {
  BlinkValue = param.asInt();
  timer.deleteTimer(timerBlinker);
  timerBlinker = timer.setInterval(BlinkValue, Func_Mode_4);
}

void Func_Mode_4() {
  led.setValue(OutputValue);
  Blynk.virtualWrite (V102, OutputValue);
  analogWrite(LedPinD1, OutputValue);
  varBlinker++;
  if (varBlinker == 1) {
    OutputValue = 255;
  }
  if (varBlinker == 2) {
    varBlinker = 0;
    OutputValue = 0;
  }
  Serial.print ("OutputValue = ");
  Serial.println (OutputValue);
}
1 Like

What are you enter here:

  BlinkValue = param.asInt(); ```
BlinkValue = ?

There I get a value from a slider on v26. With it I want control the interval from a blinking led. For example if the value I get from slider is 10 and I call the loop every 100ms, a led on output blinks with a frequency of 1Hz, when value is 1 the led blinks with 100Hz.

Be careful if you select 10 from slider, then here you start the timer with repeat rate of 10mSec due to this activation:
timerBlinker = timer.setInterval(BlinkValue, Func_Mode_4);

Try to enter a value of 250 instead of 10

Just tried. Instead of setting the slider from 1-10 is set it from 1-1000 but without success. The led usually blinks with the same frequenzy. I think there it doesn´t work because it become called three other timers at the same time

I have done some very basic timing changes here… perhaps this example will give you something to work from.

1 Like