Hey sensei! , so basically my project is control 3 led in arduino via blynk, in the blynk app i am using eventor, so if led1 on , led2 & led3 must off; led2 on, led1 % led3 must off; led3 on, led1 & led2 must off. the project works fine, but the probem is the state of widget button is not update. btw there is no physical button.
here my code:
/****************************************************************************************
* Code is based on Blynk USB-Serial Example
* Make sure you go to C:\Users\Your Username\Documents\Arduino\libraries\Blynk\scripts
* Press CTRL + LMouse Button and select Open Command Windows Here
* Then type in command windws >> blynk-ser.bat -c COM2 and click enter
* Enjoy the Virtual IoT !!!
****************************************************************************************/
#include <BlynkSimpleStream.h>
#include <SimpleTimer.h>
// Pin Assignments
int redPin=8,greenPin=9,bluePin=10;
SimpleTimer timer;
//Your app authentication token (can be fetched from your blynk app
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
BLYNK_CONNECTED(){
Blynk.syncAll();
}
BLYNK_READ(V0){
Blynk.virtualWrite(V1, LOW);
Blynk.virtualWrite(V2, LOW);
}
BLYNK_READ(V1){
Blynk.virtualWrite(V0, LOW);
Blynk.virtualWrite(V2, LOW);
}
BLYNK_READ(V2){
Blynk.virtualWrite(V0, LOW);
Blynk.virtualWrite(V1, LOW);
}
void setup()
{
//Set the three LED pins as output
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(bluePin,OUTPUT);
// Blynk will work through Serial
Serial.begin(9600);
Blynk.begin(auth, Serial);
}
void loop()
{
// All the magic is here
Blynk.run();
timer.run();
}
You seem to be running a half code, half “codeless” operation, (AKA using built in digital/analog pin control from the App). Hard to determine your projects logic flow this way.
It seems like you are running the LEDs timing from the some widgets reading rate?
Also, what button are you trying to sync the state of, and to what are you syncing it with?
I recommend you pick one method or the other… Perhaps continue to only use code control and logic for your virtual pins and enhance your code to respond to any buttons and control the digital pins as well (Digital Read & Write commands).
So in my blynk app theres 3 led button widget (circle) + eventor.
When I pressed button led1, led1 “on” , the led1 button in “on” state (switch)
When I pressed button led2, led2 “on” & led1 “off” , the led2 in “on” state (obviously). And the led1 button still in “on” state but led1 is “off”.
What I want is the led1 button is in “off” state when I pressed led2 button.
Ps: all buttons is widgets.
Thank you.
=======edited=========
Success👍
But “Simulation is not running in real time due to excessive CPU load” how to solve this?
I am using proteus8 btw
Problem solved.
Just delete all digitalWrite(X, Y).
Use Eventor and Voila!!
“Hardware” sync-ed.
Thanks for all your respons Sensei!!
Appreciate it.