Fan Control

I started working with blynk & my Nodemcu.
I’m setting different mode for controlling Fan from Menu like mannual control, time control, temperature & PIR mode.

Now i’m stuck in mannual mode at th beginning.
This is my code.

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "some token";
char ssid[] = "My_ssid";
char pass[] = "My_pass";
char server[] = "my_Localserver";
int ms1;

void setup()
{
  pinMode(D0,OUTPUT);
  Blynk.begin(auth, ssid, pass, server);
}

BLYNK_WRITE(V0) {
  switch (param.asInt())
  {
    case 1: // Mannual Switch
      if (ms1==1)
      {
        digitalWrite(D0,HIGH);
      }
      else
      {
        digitalWrite(D0,LOW);
      }
    case 2: // Time Controlled Switch
          break;
    case 3: // Temperature Controlled Automated
      break;
    case 4: // PIR Controlled Automated
      break;
    default:
      break;
  }
}

BLYNK_WRITE(V1) //When Mannual Mode enabled, this switched is used
      {
        int ms1 = param.asInt(); 
      }
      
BLYNK_WRITE(V2) //For Time controlled switch
      {
        TimeInputParam t(param);
        if (t.hasStartTime())
        {
        }
        else
        {
        }
        if (t.hasStopTime())
        {
        }
        else
        {
        }
      }

void loop()
{
  Blynk.run();
}

I have set a menu on app with output to V0.
Switch output is V1.
When i select Mannual mode in menu & trying to change state of switch, nothing happening to D0.
But i can directly change state of D0 if i use output of switch to D0
Where am i doing wrong

I think it should be as follows:

int ms1;

switch (ms1 = param.asInt())

Okay, may be i need to add flow for what i want to do.
Menu is used for which type of control i wanna use.

If selected 1, i’ll be using Mannual switch.
If selected 2, it’ll on & off according to time.(future work)
If selected 3, it’ll use selected temperature & if current temp higher, relay will be triggered.(future work)
If selected 4, It’ll use PIR.If no motion turn off relay.(future work)

ms1 is output of V1 which i need inside main menu.
so i used global var.
@coremann u can see ms1 is declared as global var.

I think you have made wrong declaration for switch case.


BLYNK_WRITE(V0) {
switch (param.asInt())
  {
    case 1: { // Mannual Switch
      Serial.println("Manul mode");
     digitalWrite(D0,HIGH);
   Manualswitch=true;
      break;
    }
    case 2: { // Item 2
      Serial.println("Item 2 selected");
      break;
    }    
  }
}

Thanks for help.
thought indentation is enough
damn c++.
anyway i had to call a function from loop to check status of mode & other continuously to make it work properly.

No need of such things.
Use Blynk.syncVirtual(pin); after connected to Blynk.and when you select items from menu it automatically sync or change the case.
For manul mode loop use such condition.

BLYNK_WRITE(V1) //When Mannual Mode enabled, this switched is used { int ms1 = param.asInt(); if((ms1=1)&&(manulswitch=true)) { digitalWrite(D0,HIGH); } else{ digitalWrite(D0,LOW); } }