//Konfigurasi Blynk
#define BLYNK_TEMPLATE_ID "TMPL6uRibrw9B"
#define BLYNK_TEMPLATE_NAME "Temanku PetFeeder"
#define BLYNK_AUTH_TOKEN "GH8HdM13cguyOZHSuO_o8ii4Gv4UgEMM"
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#define USE_NODE_MCU_BOARD
//Konfigurasi library
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <NTPClient.h>
#include <TimeLib.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <BlynkSimpleEsp8266.h>
//Konfigurasi alat
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo Baling;
//Konfigurasi wifi & ntp clock
const char *auth = BLYNK_AUTH_TOKEN;
const char *ssid = "Amogus"; //wifi ssid
const char *password = "69420911"; //wifi password
const long utcOffsetInSeconds = 28800; // set offset
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "id.pool.ntp.org", utcOffsetInSeconds);
//Konfigurasi Timer Manual
int haha[][3] {{10, 53, 5},{10,54, 10},{10,55, 15},{10, 56, 20}};
int indexing = 0;
int max_timer = 4;
//Konfigurasi jam
char Time[ ] = "Jam: 00:00:00";
char Date[ ] = "Tgl: 00/00/2000";
byte last_second, second_, minute_, hour_, day_, month_;
int year_;
//Konfigurasi Variabel lainnya yang dipakai
int final_time, data, timer_blynk1, timer_blynk2,takaran;
int c1 = 0;
int baling_speed = 180;
//---------------------------------------------------------//
//Code untuk ditampilkan di blynk
BLYNK_WRITE(V0) {
data = param.asInt();
}
BLYNK_WRITE(V1) {
timer_blynk1 = param.asInt();
Serial.println("Got The Time");
}
BLYNK_WRITE(V2) {
timer_blynk2 = param.asInt();
Serial.println("Got The Time");
}
BLYNK_WRITE(V3) {
takaran = param.asInt();
}
//---------------------------------------------------------//
void setup() {
Serial.begin(115200);
lcd.init(); // Initialize 16x2 LCD Display
lcd.backlight();
lcd.clear();
lcd.setCursor (0,0); // column, row
lcd.print("Created by:");
lcd.setCursor (0,1); // column, row
lcd.print("Temanku Inc.");
delay(4000);
lcd.clear();
lcd.setCursor (0,0); // column, row
lcd.print("Searching WiFi..");
delay(2000);
lcd.setCursor (0,1); // column, row
lcd.print("Connected!");
delay(1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(Time);
lcd.setCursor(0, 1);
lcd.print(Date);
WiFi.begin(ssid, password);
Serial.print("Connecting.");
while ( WiFi.status() != WL_CONNECTED ) {
delay(500);
Serial.print(".");
}
Serial.println("connected");
timeClient.begin();
Blynk.begin(auth, ssid, password, "blynk.cloud", 80);
Baling.attach(D3);
}
void loop() {
timeClient.update();
unsigned long unix_epoch = timeClient.getEpochTime(); // Get Unix epoch time from the NTP server
unsigned int HH = timeClient.getHours();
unsigned int MM = timeClient.getMinutes();
unsigned int SS = timeClient.getSeconds();
final_time = HH*3600 + MM*60 + SS;
second_ = second(unix_epoch);
if (last_second != second_) {
minute_ = minute(unix_epoch);
hour_ = hour(unix_epoch);
day_ = day(unix_epoch);
month_ = month(unix_epoch);
year_ = year(unix_epoch);
Time[12] = second_ % 10 + 48;
Time[11] = second_ / 10 + 48;
Time[9] = minute_ % 10 + 48;
Time[8] = minute_ / 10 + 48;
Time[6] = hour_ % 10 + 48;
Time[5] = hour_ / 10 + 48;
Date[5] = day_ / 10 + 48;
Date[6] = day_ % 10 + 48;
Date[8] = month_ / 10 + 48;
Date[9] = month_ % 10 + 48;
Date[13] = (year_ / 10) % 10 + 48;
Date[14] = year_ % 10 % 10 + 48;
Serial.println(Time);
Serial.println(Date);
lcd.setCursor(0, 0);
lcd.print(Time);
lcd.setCursor(0, 1);
lcd.print(Date);
last_second = second_;
//Servo dengan timer manual
if (HH == haha[indexing][0] && MM == haha[indexing][1] && SS <= 4){
ServoKing(haha[indexing][2]);
indexing++;
if (indexing == max_timer){
indexing = 0;
}
}
//Servo dari blynk V1
Timer_Blynk(timer_blynk1);
Timer_Blynk(timer_blynk2);
//Tombol blynk V0
if (data == 1 && c1 == 0){
Baling.write(baling_speed);
c1 = 1;
On_Feeding();
delay(3000);
} else if (data == 0 && c1 == 1){
Baling.write(90);
c1 = 0;
Off_Feeding();
delay(3000);
lcd.clear();
}
}
delay(25);
Blynk.run();
}