Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
1.3 kB
2
Indexable
Never
#include <BlynkSimpleEsp32.h>
#include <WiFi.h>
#include <ESP32Servo.h>
#include <ToneESP32.h>

Servo myservo;

int StatusPakan;

#define BLYNK_TEMPLATE_ID "TMPL63rxqzZfl"
#define BLYNK_TEMPLATE_NAME "UAP"
#define BLYNK_AUTH_TOKEN "QjB_HnT08i_Vw1H8ryoAPWQp47n1lQWd"
#define buzzerPin 4


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(buzzerPin, OUTPUT);
  myservo.attach(18);
  myservo.write(0);
  WiFi.begin("Woy Jangan Usil", "lunasiduluboss");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi...");
  }
  Serial.println("Connected to WiFi");

  Blynk.begin(BLYNK_AUTH_TOKEN, "Woy Jangan Usil", "lunasiduluboss");
}

void feed(){
  
  for(int posisi = 0; posisi <= 180; posisi++){
    myservo.write(posisi); // Buka servo
    delay(10);
  }
  for(int posisi = 180; posisi >= 0; posisi--){
    myservo.write(posisi); // Tutup servo
    delay(10);
  }
  
}

void loop() {
  Blynk.run();

  Serial.println("Status Pakan : " + String(StatusPakan));
  if (StatusPakan == 1){
    feed();
    digitalWrite(buzzerPin, HIGH);
    delay(3000);
    digitalWrite(buzzerPin, LOW);
  }

  Blynk.virtualWrite(V0, 0);
  StatusPakan = 0;
  delay(2000);
}

BLYNK_WRITE(V0)
{
  StatusPakan = param.asInt();
}