// Code generated by Arduino IoT Cloud
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 display(128, 64, &Wire, -1);
const char DEVICE_LOGIN_NAME[] = "373bb0e9-5f46-48b8-8f42-f73a1e9a359d";
const char SSID[] = "Wokwi-GUEST";
const char PASS[] = "";
const char DEVICE_KEY[] = "1tRg0UWO#tbA7r?xeS20xgUOz";
void onJadwal1Change();
void onJadwal2Change();
void onJadwal3Change();
void onJadwal4Change();
void onJadwal5Change();
time_t UnixTime;
unsigned long skr = 0;
String waktu;
bool r1 = false, r2 = false, r3 = false, r4 = false, r5 = false;
int a = 0, b = 0, c = 0, d = 0, e = 0;
CloudSchedule jadwal1;
CloudSchedule jadwal2;
CloudSchedule jadwal3;
CloudSchedule jadwal4;
CloudSchedule jadwal5;
void initProperties() {
ArduinoCloud.setBoardId(DEVICE_LOGIN_NAME);
ArduinoCloud.setSecretDeviceKey(DEVICE_KEY);
ArduinoCloud.addProperty(jadwal1, READWRITE, ON_CHANGE, onJadwal1Change);
ArduinoCloud.addProperty(jadwal2, READWRITE, ON_CHANGE, onJadwal2Change);
ArduinoCloud.addProperty(jadwal3, READWRITE, ON_CHANGE, onJadwal3Change);
ArduinoCloud.addProperty(jadwal4, READWRITE, ON_CHANGE, onJadwal4Change);
ArduinoCloud.addProperty(jadwal5, READWRITE, ON_CHANGE, onJadwal4Change);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
void setup() {
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for (;;);
}
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
pinMode(23, OUTPUT);
pinMode(19, OUTPUT);
pinMode(18, OUTPUT);
pinMode(5, OUTPUT);
pinMode(17, OUTPUT);
}
void loop() {
ArduinoCloud.update();
if (jadwal1.isActive()) {
digitalWrite(23, HIGH);
r1 = true;
}
else {
digitalWrite(23, LOW);
r1 = false;
}
if (jadwal2.isActive()) {
digitalWrite(19, HIGH);
r2 = true;
}
else {
digitalWrite(19, LOW);
r2 = false;
}
if (jadwal3.isActive()) {
digitalWrite(18, HIGH);
r3 = true;
}
else {
digitalWrite(18, LOW);
r3 = false;
}
if (jadwal4.isActive()) {
digitalWrite(5, HIGH);
r4 = true;
}
else {
digitalWrite(5, LOW);
r4 = false;
}
if (jadwal5.isActive()) {
digitalWrite(17, HIGH);
r5 = true;
}
else {
digitalWrite(17, LOW);
r5 = false;
}
if (millis() - skr > 1000) {
UnixTime = ArduinoCloud.getLocalTime();
waktu = ctime(&UnixTime);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.print(waktu.substring(0, 11));
display.print(waktu.substring(20));
display.print(" ");
display.println(waktu.substring(11, 19));
if (r1) {
a++;
display.print("R1:ON.......");
display.println(a);
} else {
a = 0;
display.println("R1:OFF.........");
}
if (r2) {
b++;
display.print("R2:ON.......");
display.println(b);
} else {
b = 0;
display.println("R2:OFF.........");
}
if (r3) {
c++;
display.print("R3:ON.......");
display.println(c);
} else {
c = 0;
display.println("R3:OFF.........");
}
if (r4) {
d++;
display.print("R4:ON.......");
display.println(d);
} else {
d = 0;
display.println("R4:OFF.........");
}
if (r5) {
e++;
display.print("R5:ON.......");
display.println(e);
} else {
e = 0;
display.println("R5:OFF.........");
}
display.display();
skr = millis();
}
}
void onJadwal1Change() {
}
void onJadwal2Change() {
}
void onJadwal3Change() {
}
void onJadwal4Change() {
}
void onJadwal5Change() {
}