«

»

Jun 23

ESP8266 dan Blynk

Di era tsunami Internet of Things (IoT), ada banyak solusi kreatif yang hadir, untuk membantu pengembang dalam implementasi sistem berbasis IoT secara cepat dan mudah. Dan kita sama-sama melihat kecenderungan ini.

Bila ingin mendalami IoT, silahkan menghubungi Padepokan NEXT SYSTEM Bandung – edukasi.nextsys.web.id.

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

char auth[] = "xxxxx";
unsigned long ledBlink;

WidgetLED ledGreen(V3);

void setup()
{
  Serial.begin(9600);
  pinMode(2,OUTPUT);
  digitalWrite(2,HIGH);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  pinMode(16,OUTPUT);
  digitalWrite(16,HIGH);
  Blynk.begin(auth, ssid, password);
}

BLYNK_WRITE(V0) {
    if (param.asInt()==0) { 
        digitalWrite(2, HIGH);
    }
    else {
        digitalWrite(2, LOW);  
    }
}

BLYNK_WRITE(V1) {
    if (param.asInt()==0) {   
        digitalWrite(4, HIGH);
    }
    else {
        digitalWrite(4, LOW);  
    }
}

BLYNK_WRITE(V2) {
    if (param.asInt()==0) {   
        digitalWrite(16, HIGH);
    }
    else {
        digitalWrite(16, LOW);
    }
}

void loop()
{
  Blynk.run();
  if ( millis() - ledBlink >= 1000 ) {
     if ( digitalRead(2) == LOW )
       ledGreen.on();
//       Blynk.virtualWrite(V3,1023);
     else
       ledGreen.off();
//       Blynk.virtualWrite(V3,0);  
     ledBlink = millis();  
  }
}