// Tugas Kelompok 4 Kontrol Servo dengan Blynk
// Project Pakan Ayam Secara Otomatis dan bisa secara manual dengan Blynk
#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "TMPL8VVMSH_P"
#define BLYNK_DEVICE_NAME "Tugas Topik 9 Kelompok 4"
#define BLYNK_AUTH_TOKEN "rez-_P6JEPF3dq2_gU2Jxy7KZE5XvcSx"
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <ESP32Servo.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "RTClib.h"
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
#define TINGGI_LAYAR 64 // Tinggi layar OLED yang digunakan
#define LEBAR_LAYAR 128 // Lebar layar OLED yang digunakan
Servo myservo;
RTC_DS3231 rtc; // Using DS3231 Real Time Clock
//OLED
Adafruit_SSD1306 oled(LEBAR_LAYAR, TINGGI_LAYAR, &Wire, -1);
void setup() {
myservo.attach(15);
myservo.write(0);
Blynk.begin(auth, ssid, pass);
Serial.begin(115200);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC. Dead now.");
Serial.flush();
while (1) delay(10);
}
// rtc.adjust(DateTime(2022, 2, 14, 0, 0, 0));
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
oled.clearDisplay();
oled.setTextSize(1); // Atur ukuran text
oled.setTextColor(WHITE); // Atur warna text
oled.setCursor(20, 20); // Atur posisi text pada display
oled.println("WELCOME PAKAN AYAM"); // Text yang dicetak
delay(2000);
oled.display();
oled.clearDisplay();// menampilkan display OLED
}
BLYNK_WRITE(V0){
DateTime now = rtc.now();
oled.clearDisplay();
myservo.write(param.asInt());
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print(param.asInt()); //Tampilan LCD
oled.print("Derajat"); //Tampilan LCD
// oled.setCursor(0, 23);
//oled.print(Y); display.print(" years, ");
//oled.setCursor(0, 35);
//oled.print(M); display.print(" months and ");
//oled.setCursor(0, 47);
//oled.print(D); display.println(" days.");
oled.display();
}
// Membuka Penuh Pakan
BLYNK_WRITE(V3){
oled.clearDisplay();
myservo.write(180);
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print("Pakan Buka Penuh"); //Tampilan LCD
oled.display();
}
// Membuka Separo Pakan
BLYNK_WRITE(V2){
oled.clearDisplay();
myservo.write(90);
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print("Pakan Setengah"); //Tampilan LCD
oled.display();
}
// Menutup Pakan
BLYNK_WRITE(V1){
oled.clearDisplay();
myservo.write(0);
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(0,10);
oled.print("Pakan Ditutup"); //Tampilan LCD
oled.display();
}
void loop() {
Blynk.run();
DateTime now = rtc.now();
oled.clearDisplay();
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.setCursor(20,20);
oled.print(now.hour());
oled.print(" : ");
oled.print(now.minute());
oled.print(" : ");
oled.print(now.second());
oled.display();
if((now.hour() == 2) && (now.minute() == 19) ) {
myservo.write(180);
delay(3000);
myservo.write(0);
}
}