Help me sync button widget state to hardware state (arduino)

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

sorry about my english,
Thank you.

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

1 Like

Or maybe a segmented switch with 3 positions?

Pete.

1 Like

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.

The thread title is edited.

use the segmented switch as @PeteKnight suggested. :wink:

1 Like

=======edited=========
Success👍
But “Simulation is not running in real time due to excessive CPU load” how to solve this?
I am using proteus8 btw :thinking:

1 Like

why don’t you use a real MCU ?

1 Like

We help with Blynk and occasionally give advice with hardware. But hardware simulators? Nope, you need to ask their support forum, not here :wink:

1 Like

I want to learn the simulation first before buy the actual hardware.

1 Like

NodeMCU only cost 2.70$

1 Like

OK, I will go there.

OK, can I change the question?

  BLYNK_CONNECTED(){
  Blynk.syncAll();
  }

BLYNK_WRITE(V3) {
   switch (param.asInt())
  {
    case 1: {
     digitalWrite(8, 1);
     digitalWrite(9, 0);
     digitalWrite(10, 0);
    break;
    }
    case 2: {
    digitalWrite(9, 1);
    digitalWrite(8, 0);
    digitalWrite(10, 0);
    break;
   }
   case 3: {
   digitalWrite(10, 1);
   digitalWrite(8, 0);
   digitalWrite(9, 0);   
    break;
  } 
    case 4: {
       digitalWrite(8, 0);
     digitalWrite(9, 0);
     digitalWrite(10, 0);
    break;      
    }
   }
  }

Why BLYNK_CONNECTED(){
Blynk.syncAll();
}
can’t sync state of hardware from app?

It will… with real hardware at least.

1 Like

Which one you recommend, the nodemcu v1/v2/v3 for optimized aquarium? (3led, temp sensor, servo, oxygen & pH sensor)

Thanks

Whatever latest NodeMCU or Wemos D1 Mini you can get (they are all basically the same ESP8266 chip on a development board)

1 Like

3.50 $
https://rover.ebay.com/rover/0/0/0?mpre=https%3A%2F%2Fwww.ebay.com.au%2Fulk%2Fitm%2F263889248270

1 Like

Problem solved.
Just delete all digitalWrite(X, Y).
Use Eventor and Voila!!
“Hardware” sync-ed.
Thanks for all your respons Sensei!!
Appreciate it.:man_student:

1 Like