2018年11月11日 星期日

ESP32 to Control LED With Blynk Via WiFi

ESP32 to Control LED With Blynk Via WiFi


#define BLYNK_PRINT Serial

int LEDpin        = 2;   //build in LED

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

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
//char auth[] = "Your auth token key";
char auth[] = "25caf73aa9374cdf9220df77c848980a";

// Your WiFi credentials.
// Set password to "" for open networks.
//char ssid[] = "Your network name";
//char pass[] = "Your network password";
char ssid[] = "alex9ufo";
char pass[] = "alex9981";
//===========================================
WidgetLED led1(V1); //register to virtual pin 1
void led_status() { 
     Serial.print("Blynk LED pin status :");
     int pinvalue = digitalRead (LEDpin);
     Serial.println(String(pinvalue).c_str());
    if (pinvalue==HIGH){
        led1.on();
        }
    else{
        led1.off();
      }
}
//===========================================
void setup() {  
  pinMode(LEDpin, OUTPUT); 
  pinMode(LEDpin, HIGH);
  Serial.begin(115200);

  delay(10);
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected");  
  Blynk.begin(auth , ssid, pass);

}
//===========================================
void loop(){
    Blynk.run();
    led_status(); 
    
}
//===========================================













沒有留言:

張貼留言

113 學年度第 1 學期 RFID應用課程 Arduino程式

113 學年度第 1 學期 RFID應用課程 Arduino程式 https://www.mediafire.com/file/zr0h0p3iosq12jw/MFRC522+(2).7z/file 內含修改過後的 MFRC522 程式庫 (原程式有錯誤) //定義MFRC522...