top of page

#include <SPI.h>
#include <SimpleTimer.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

//Config ขา Output
#define fornA D1 //
#define backA D2 //
#define fornB D3 //
#define backB D4 //


 
char auth[] = " _UzmMyYkaU1qvjiVj3lQ4waXM5WYNnF5";              // Blynk Tovken 
char ssid[] = "AndroidAPFCD8"; // ชื่อ WIFI
char pass[] = "wasanfern";     // รหัสผ่าน


WidgetLED BT1Blynk(V10);
WidgetLED BT2Blynk(V11);
WidgetLED BT3Blynk(V12);
WidgetLED BT4Blynk(V13);

void setup()
{
  // Debug console
  Serial.begin(9600);
  
  //กำหนดขา OUTPUT
  pinMode(fornA,OUTPUT); 
  pinMode(backA,OUTPUT); 
  pinMode(fornB,OUTPUT); 
  pinMode(backB,OUTPUT); 

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

  BLYNK_CONNECTED() { 
  Blynk.syncVirtual(V1); 
  Blynk.syncVirtual(V2); 
  Blynk.syncVirtual(V3); 
  Blynk.syncVirtual(V4); 
  
 }
void loop()
{
  Blynk.run();
}
BLYNK_WRITE(V1){ 
  Serial.println(param.asInt()); 
    if (param.asInt()){ 
        digitalWrite(fornA, LOW); 
        digitalWrite(backA, HIGH); 
        digitalWrite(fornB, LOW); 
        digitalWrite(backB, HIGH);
        
        BT1Blynk.off();
    } else {
        digitalWrite(fornA, HIGH); 
        digitalWrite(backA, HIGH); 
        digitalWrite(fornB, HIGH); 
        digitalWrite(backB, HIGH);
         BT1Blynk.on();
    }
}
BLYNK_WRITE(V2){ 
  Serial.println(param.asInt()); 
    if (param.asInt()){ 
        digitalWrite(fornA, HIGH); 
        digitalWrite(backA, LOW); 
        digitalWrite(fornB, HIGH); 
        digitalWrite(backB, LOW);
        BT2Blynk.on();
    } else {
        digitalWrite(fornA, HIGH); 
        digitalWrite(backA, HIGH); 
        digitalWrite(fornB, HIGH); 
        digitalWrite(backB, HIGH);
         BT2Blynk.off();
    }
}
BLYNK_WRITE(V3){ 
  Serial.println(param.asInt()); 
    if (param.asInt()){ 
        digitalWrite(fornA, LOW); 
        digitalWrite(backA, HIGH); 
        digitalWrite(fornB, HIGH); 
        digitalWrite(backB, LOW);
        BT4Blynk.on();
    } else {
        digitalWrite(fornA, HIGH); 
        digitalWrite(backA, HIGH); 
        digitalWrite(fornB, HIGH); 
        digitalWrite(backB, HIGH);
         BT4Blynk.off();
    }
}
BLYNK_WRITE(V4){ 
  Serial.println(param.asInt());
    if (param.asInt()){ 
        digitalWrite(fornA, HIGH); 
        digitalWrite(backA, LOW); 
        digitalWrite(fornB, LOW); 
        digitalWrite(backB, HIGH);
        BT3Blynk.on();
    } else {
        digitalWrite(fornA, HIGH); 
        digitalWrite(backA, HIGH); 
        digitalWrite(fornB, HIGH); 
        digitalWrite(backB, HIGH);
         BT3Blynk.off();
    }
}
 

bottom of page