If I have a serial monitor open to debug my program, and I slide the slider widget to change a value in the program, Arduino crashes. Is this an issue, or something I’m overlooking?
I have tried with multiple widgets, holding the button down while in Push mode doesn’t have the same effect as continuously sliding the slider.
I have the same problem with my Arduino Nano and the slider. My slider is polled every second and then the reading sent back to a Value Display in the App. If I slide the slider then I get errors in the serial window and the connection to the Blynk server needs to be restarted. If I prod or dab the slider all works fine. Perhaps this is a ‘flood’ issue?
For me the slider range is very small, just 10 to 30 but I think dragging the slider is just too much ‘stress’ for the Nano / Blynk server. Anybody found a fix for delaying the slider readings until you stop sliding?
I’m not sure the logic here is spot on, but you can do something like this to compare current time with a previous time and if current time - previous time is bigger than the interval, do something, but I’m not sure it’ll work correct this way.
-edit-
Or use the debounce library, I think someone already made something for de-bouncing buttons, I’m sure that’ll work here too.
Lichtsignaal I have 2 (well 3 timers) one that calls read slider and one that writes slider value to a value display.They are both set at 1 second intervals (the third for something else is 6 second intervals).
So I have:
void sendMinutes()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V6, minutes_requested); // StartTimer (manual) duration in minutes write to V6 every second
}
void sendSlider()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V6, minutes_requested); // StartTimer (manual) duration in minutes write to V6 every second
}
BLYNK_WRITE(V7) //Button Widget is writing to pin V7
{
int pinData2 = param.asInt();
minutes_requested = pinData2;
}
And in setup I have:
timer.setInterval(1000L, sendMinutes); // send every 1 second
timer.setInterval(1000L, sendSlider); // send every 1 second
Wouldn’t the timer library overwrite the millis debounce?
I do need to do some debounce as some of my pins appear to be floating. Fixed one with an LED but don’t want to put LED’s on all the bouncing pins.
Dimitriy not sure if code snippets are any good for you. Is it ok to write 2 lots of details to a single value display?
Dimitriy do you know what the frequency is for reading the Slider? I have set up some basic code and I can now slide the Slider and report the changes on a Value Display widget.
But if I move the slider back and forwards too quickly the system crashes. I will incorporate millis() into my sketch as suggested by Lichtsignaal but I’m not convinced this will fix the problem if your slider value calls are too frequent.
I show the full sketch below. Initial previousMillis = millis(); is in setup() and resetting if the action is carried out in V7. Even with the wait time set as high as 1500 ms it will not prevent the crash. As far as I can tell it is not the writing to the Value Display widget that is the problem (following Lichtsignaal’s fix) it is the constant reading of the Slider. I guess the Slider frequency is set at your end. With my cleaner code the normal operation of the slider is now fine but you are always going to get some user who wants to fly backwards and forwards at unacceptable speeds.
/**************************************************************
Simple NANO reboot sketch 26/12/2015
**************************************************************/
#include <SoftwareSerial.h>
SoftwareSerial SwSerial(11, 12); // RX, TX was 2 and 3
#define BLYNK_PRINT SwSerial
#define BLYNK_DEBUG // Optional, this enables lots of prints
#include <BlynkSimpleSerial.h>
#include <SimpleTimer.h>
SimpleTimer timer;
int testval = 0; // variable to hold D3 pin status
int Changed = 0; // variable to see if D3 pin status has changed
int TestLEDPin = 3; // new ON / OFF LED PIN
int minutes_requested = 0;
int pinData2 = 0; // read Slider vlaue
int SliderChanged = 0; // check if slider value has changed
unsigned long previousMillis;
unsigned long waitTime = 1500;
char auth[] = "2120f1064e494868aa6f624c48a0ebcd";
void setup()
{
SwSerial.begin(9600);
SwSerial.println(" Nano has just rebooted");
Blynk.begin(auth);
timer.setInterval(1000L, sendSlider); // send every 1 second
pinMode(TestLEDPin, OUTPUT);
digitalWrite(TestLEDPin, LOW); // set LED pin OFF
delay(50); // wait 0.15 seconds
previousMillis = millis(); // set initial values as equal
}
//****************************************
BLYNK_WRITE(V7) //Button Widget is writing to pin V7
{
if( ( millis() - previousMillis ) >= waitTime )
{
pinData2 = param.asInt();
if (pinData2 != SliderChanged){ // Slider has changed
minutes_requested = pinData2;
previousMillis = millis();
}
}
}
void sendSlider()
{
if (pinData2 == SliderChanged){ // Slider hasn't changed
minutes_requested = millis()/ 1000; // 1 second intervals
}
pinData2 = SliderChanged; // set variables the same
Blynk.virtualWrite(V6, minutes_requested); // StartTimer (manual) duration in minutes write to V6 every second
}
//void(* resetFunc) (void) = 0; //declare reset function @ address 0 THIS IS VERY USEFUL
void loop()
{
Blynk.run();
timer.run(); // Initiates SimpleTimer
testval = digitalRead(TestLEDPin); // pin
delay(100);
if (testval != Changed){ // prevent looping until status of D3 pin changes
if (testval == 1){
SwSerial.println(" Pin is HIGH resetting Nano .............");
delay(200); // pause to see LED ON prior to reset
//resetFunc(); // reset Nano
}
else{
SwSerial.println(" OK Pin is LOW");
}
Changed = testval; // prevent looping until status of D3 pin changes
}
}