May I use instruction “Blynk.virtualWrite(V0, value)” update app’s widget of “slider”?
I design a physical slider , hope my physical slider could update to app’s slider.
My code is:
int number=1;
void loop() {
Blynk.run();
}
BLYNK_READ(V0){
if(number>6){
number=0;
Blynk.virtualWrite(V0, number++);
}
else {
Blynk.virtualWrite(V0, number++);
}
}
// I don’t got good result what is I want.
1 Like
Costas
October 18, 2016, 7:39am
2
Yes you can update the slider but don’t do the ++ in the virtualWrite function.
1 Like
I change my code as:
int number;
void loop() {
Blynk.run();
}
BLYNK_READ(V0){
number=random(0, 6);
Blynk.virtualWrite(V0, number);
}
I don’t have ideal result. sider is unchange.
You need to engage Blynk.sync(0); somewhere. That’ll sync the slider to the value.
I think, you don’t clear my idea.
"sync()"is harware update from app widget, is not update new data to app’s slider.
I want to update app’s sider’s value/status, real time data from hardware.
result is my app’s slider unchanged…
Lichtsignaal:
Yes it is.
It is not
Your screenshot not clickable. Don’t see anything. Please show larger screenshots.
Wait, am I really missing something here? I use blynk.sync to sync from my hardware to the app. What am I doing wrong because it works fine
Dmitriy
October 18, 2016, 8:21am
10
Look like yes. sync for app → hardware. Blynk.virtualWrite
for hard → app.
Dmitriy
October 18, 2016, 8:23am
11
@YangfengYuWen Look like your problem it that you enabled mapping in widget settings (small circle between min-max)
Dmitriy
October 18, 2016, 8:25am
13
@YangfengYuWen Looks like your problem it that you enabled mapping in widget settings (small circle between min-max)
See http://docs.blynk.cc/#widgets-common-widget-settings-data-mapping for more details.
int number;
void loop() {
Blynk.run();
}
BLYNK_READ(V0){
number=random(0, 6);
Blynk.virtualWrite(V0, number);
Serial.println(number);
}
I still don’t see app’s slider change.
Serial.print no data from serial.
Dmitriy
October 18, 2016, 8:36am
16
YangfengYuWen:
BLYNK_READ(V0){
You need to use timer with Blynk.virtualWrite
. Please see basic example for that.
BLYNK_READ(V0)
is for widgets with frequency reading property.
Thank you everyone, I solved it. Code is :
void setup{
WiFi.printDiag(Serial);
Blynk.config(auth);
}
unsigned long Timer = millis();
void loop() {
Blynk.run();
while((millis()-Timer)>2000){
Blynk.virtualWrite(V0, random(0, 6));
Blynk.virtualWrite(V1, random(0, 255));
Timer = millis();
}
}
forgot “Blynk.config(auth);”
2.Wrong set:
3.Right Set:
first of all ,delete BLYNK_READ(V0){ },
use “Blynk.virtualWrite(V0, random(0, 6));” in Loop is well.
and close “DATA MAPING”
Thanks a lot, Dmitriy.
Costas
October 18, 2016, 1:34pm
19
@Yangfeng if that is your complete sketch and you don’t want to progress to bigger and better things then it is fine. The recommended way is with the library provided by Blynk called SimpleTimer (there’s a clue there in the name of the library).
Dose “SimpleTimer.h” adapt Nodemcu?