ผมขอแนวทางการทำระบบ Auto/Manual หน่อยครับ

โค้ดแบบนี้ต้องต่อยังไงบ้างครับ

#define BLYNK_TEMPLATE_ID "TMPLxkfmRohc"
#define BLYNK_DEVICE_NAME "SmartFarm 2"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
#define DHTPIN 15
#define DHTTYPE DHT11
//#define APP_DEBUG
#define USE_NODE_MCU_BOARD
#define USE_WROVER_BOARD
#include "BlynkEdgent.h"
#include <DHT.h>
DHT dht(DHTPIN, DHTTYPE);
int SensorPin = A0;
int SensorValue = 0;

const int moisture1 = 32;
const int moisture2 = 33;
const int moisture3 = 34;
const int moisture4 = 35;
int moisture_value1 = 0;
int moisture_value2 = 0;
int moisture_value3 = 0;
int moisture_value4 = 0;
bool switchStatus = 0; // 0 = manual,1=auto
int soilMoistureLimit = 0;
bool manualSwitch = 0;
bool solenoid1 = 0;
bool solenoid2 = 0;
BLYNK_WRITE(V0)
{   
  switchStatus = param.asInt(); // Get value as integer
}
// update soilMosture setting
BLYNK_WRITE(V1)
{
  soilMoistureLimit = param.asInt(); // Get value as integer
}
// update manualSwitch
BLYNK_WRITE(V5)
{
  manualSwitch = param.asInt();
}

BLYNK_WRITE(V6)
{
  solenoid1 = param.asInt();
}

BLYNK_WRITE(V7)
{
  solenoid2 = param.asInt();
}
#define PUMP D0
#define relayone D2
#define relaytwo D3

void manualAutoAction()
{
  moisture_value1 = analogRead(moisture1);
  moisture_value2 = analogRead(moisture2);
  moisture_value3 = analogRead(moisture3);
  moisture_value4 = analogRead(moisture4);
  Serial.print("Moisture1 = ");
  Serial.println(moisture_value1);
  delay(500);
  Serial.print("Moisture2 = ");
  Serial.println(moisture_value2);
  delay(500);
  Serial.print("Moisture3 = ");
  Serial.println(moisture_value3);
  delay(500);
  Serial.print("Moisture4 = ");
  Serial.println(moisture_value4);
  delay(500);
  if(switchStatus)
  {
    // auto
    if(moisture_value1 < soilMoistureLimit||(moisture_value2 < soilMoistureLimit))
    {
      digitalWrite(PUMP,HIGH);
      digitalWrite(relayone,HIGH);
    }  
    else
    {
      digitalWrite(PUMP,LOW);
      digitalWrite(relayone,LOW);
    }
     {
    if(moisture_value3 < soilMoistureLimit||(moisture_value4 < soilMoistureLimit))
    {
      digitalWrite(PUMP,HIGH);
      digitalWrite(relaytwo,HIGH);
    }  
    else
    {
      digitalWrite(PUMP,LOW);
      digitalWrite(relaytwo,LOW);
    }
  }
}
  //manual
  else
  {
    if(manualSwitch)
    {
      digitalWrite(PUMP,HIGH);
    }
    else
    {
      digitalWrite(PUMP,LOW);
    }

    if(solenoid1)
    {
      digitalWrite(relayone,HIGH);
    }
    else
    {
      digitalWrite(relayone,LOW);
    }

    if(solenoid2)
    {
      digitalWrite(relaytwo,HIGH);
    }
    else
    {
      digitalWrite(relaytwo,LOW);
    }
    // manaul
  }
}

void checkTemp()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  Blynk.virtualWrite(V5, h);  //V5 is for Humidity
  Blynk.virtualWrite(V6, t);  //V6 is for Temperature
}
void setup()
{
  Serial.begin(9400);
  delay(100);
  pinMode(PUMP,OUTPUT);
  digitalWrite(PUMP,HIGH);
  digitalWrite(PUMP,LOW);
  pinMode(relayone,OUTPUT);
  digitalWrite(relayone,HIGH);
  digitalWrite(relayone,LOW);
  pinMode(relaytwo,OUTPUT);
  digitalWrite(relaytwo,HIGH);
  digitalWrite(relaytwo,LOW);
  BlynkEdgent.begin();
  timer.setInterval(1000L, manualAutoAction);
  timer.setInterval(10000L, checkTemp);

}
void loop() {
  BlynkEdgent.run();
  SensorValue = analogRead(SensorPin);
  SensorValue = map(SensorValue, 0, 1023, 0, 100);
  Blynk.run();
  timer.run();
}

เบื้องต้นทำทีระบบครับเริ่มจาก Manual ก่อน อันนี้เสร็จหรือยังติดปัญหาหรือไม่

ลองศึกษาดูครับ

/**
 คือผมอยากทำ auto / manual ควบคุมผ่านแอพ blynk
โดยผมจะใช้ Widget timer1ตัว Button 2ตัว ตัวนึงเลือก auto ตัวนึงเลือก manual

การทำงานคือ

กดปุ่ม manual รีเลย์ทำงานทันที
กดปุ่ม auto ตั้งเวลาทำงานด้วย timer เมื่อถึงเวลาที่ตั้งไว้รีเลย์ถึงจะทำงาน

ผมรบกวนขอ Code ตัวอย่างการเขียนทีครับ 
 */
#define BLYNK_PRINT Serial

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>


char auth[] = "Xnhm5TOl77FI1Vmyw-ZvJu5ge73Q_pgi";
char server1[] = "oasiskit.com";

char ssid[] = "Nu-Electronic";
char pass[] = "228228228";

int Auto_mode;
int Man_mode;
int Timer1;




#define led1 25
#define led2 26




BLYNK_WRITE(V1)//กดปุ่ม on off Auto mode
{

  int pinValue = param.asInt();
  if (pinValue == 1) {
    Auto_mode = 1;
    Auto_ON();

  }
  if (pinValue == 0) {
    Auto_mode = 0;
  }
}

void Auto_ON() {

  Man_mode = 0;
  Blynk.virtualWrite(V2, 0);

}



BLYNK_WRITE(V2)//กดปุ่ม on off Manual mode
{

  int pinValue = param.asInt();
  if (pinValue == 1) {
    Man_mode = 1;
    Man_ON();

  }
  if (pinValue == 0) {
    Man_mode = 0;

  }
}

void Man_ON() {
  Auto_mode = 0;
  Blynk.virtualWrite(V1, 0);
}


BLYNK_WRITE(V3)//ตั้งเวลาปิดเปิด Relay ด้วย Timer
{

  int pinValue = param.asInt();
  if (pinValue == 1) {
    Timer1 = 1;//Timer ON


  }
  if (pinValue == 0) {
    Timer1 = 0;//Timer OFF
  }
}








void setup()
{

  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);

  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass, server1, 8080);
}







void loop()
{

  if (Man_mode == 1 and Auto_mode == 0) {

    digitalWrite(relay1 , 1);
    digitalWrite(relay2 , 1);
  }

  if (Man_mode == 0 and Auto_mode == 0) {

    digitalWrite(relay1 , 0);
    digitalWrite(relay2 , 0);
  }


  if (Man_mode == 0 and Auto_mode == 1 and Timer1 == 1 ) {

    digitalWrite(relay1 , 1);
    digitalWrite(relay2 , 1);
  }

  if (Man_mode == 0 and Auto_mode == 1 and Timer1 == 0 ) {

    digitalWrite(relay1 , 0);
    digitalWrite(relay2 , 0);
  }


  Blynk.run();
}