I have a slider on V1 that controls the overall motor speed of a quadcopter.
When moving the slider around, sometimes Blynk disconnects and it says “Connecting…” in the serial monitor.
Here is my code:
BLYNK_WRITE(V1) {
if (isQuadTurnedOn == false) {
Serial.println("Must turn quadcopter ON first!");
resetAppControls();
} else if (param.asInt() != 1 && param.asInt() != 2) { // SEPARATE IF STATEMENT USED TO AVOID SLIDER SETTING ITSELF TO 2 WHEN CONTROLLER DISCONNECTED
currentSpeed = ((maxSpeed - minSpeed) / (maxSpeed)) * param.asInt() + minSpeed; // BETWEEN 0 AND 255
Blynk.virtualWrite(V11, currentSpeed); // LED THAT DIMS USING THE VALUE OF currentSpeed
if (currentSpeed > baseSpeed) {
isLanded = false;
} else if (currentSpeed < baseSpeed / 2) {
isLanded = true;
}
if (currentSpeed > minSpeed) {
shouldStabilize = true;
} else {
shouldStabilize = false;
}
}
}
the function “resetAppControls” which is also called in the above code looks like this:
As per the Troubleshooting section of the Documentation - http://docs.blynk.cc/#troubleshooting - you are probably flooding the connection with “Too much, too fast”.
Blynk works great for IoT control… but can be tricky to utilise in a real time, fast moving, vehicular control environment.
You might have to break some of the data bursts with short timers, even “every 10-100ms” is better than “thousands of times a second”.
@andreig992 3 or 4 consecutive virtualWrite() commands is normally the maximum. Use setTimeout() function of BlynkTimer to call additional virtualWrite() commands. Test for duration but normally less than 1000ms will work.
The “problematic” command is running calculations against the slider data, that despite being really fast, still takes time - particularly noticeable when scanning slider data in real time (as opposed to send on release), while the “working” command is just taking the raw slider data.
If all you want to do is limit the range of data from the slider, then set the range in the slider widget setting
I could probably change the way the code works, but the way I wanted to do it was to ultimately set the “minSpeed” programmatically based on the user’s preference.
Is there any way to set the range of the slider’s data once (probably in the setup function), programmatically?