About use “Blynk.virtualWrite(V0, value)” update to app‘s "slider"

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

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.

Yes it is.

I want to update app’s sider’s value/status, real time data from hardware.
result is my app’s slider unchanged…

It is not :slight_smile:

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

Look like yes. sync for app → hardware. Blynk.virtualWrite for hard → app.

@YangfengYuWen Look like your problem it that you enabled mapping in widget settings (small circle between min-max)


@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.

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();
}
}

  1. 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.

@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?