Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <ESPAsyncTCP.h>
- #include <ESP8266WiFiMulti.h>
- ESP8266WiFiMulti wifiMulti;
- #include <ESPAsyncWebServer.h>
- #include <ArduinoJson.h>
- #include <Wire.h>
- #include <RTClib.h>
- #include "PrayerTimes.h"
- #include "HJS589.h"
- #include <LittleFS.h>
- #include "setting.h"
- const int buzzer = 15; // Pin GPIO Buzzer - D4
- void wifi() {
- server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
- request->send(LittleFS, "/setting.html", "text/html");
- });
- server.serveStatic("/", LittleFS, "/");
- server.onNotFound(notFound);
- server.begin();
- Serial.println("Server begin");
- Serial.println();
- }
- uint8_t tampil = 1;
- #define buzzer 3
- void setup() {
- Serial.begin(115200);
- initSPIFFS();
- readSetting();
- if (doc["state_wifi"].as<String>() == "true") {
- Serial.println("State Wifi: true");
- if (!initWiFi()) {
- hotspot();
- }
- } else if (doc["state_wifi"] == "false") {
- Serial.println("State Wifi: false");
- hotspot();
- }
- Disp_init();
- Disp.setBrightness(50);
- Serial.println("Display init");
- Serial.println();
- while (!rtc.begin()) {
- Serial.println("Clear I2C");
- I2C_ClearBus();
- delay(250);
- if (!rtc.begin()) {
- Serial.println("Couldn't find RTC");
- //while (1);
- }
- }
- wifi();
- //Buzzer
- pinMode(buzzer, OUTPUT);
- }
- void beep() {
- DateTime now = rtc.now();
- if (now.minute() == 0 && now.hour() != 12 && now.hour() != 0 && now.hour() != 6 && now.hour() != 18 && now.second() < 1) {
- digitalWrite(buzzer, HIGH);
- delay(250);
- digitalWrite(buzzer, LOW);
- }
- if (now.hour() == 6 || now.hour() == 12 || now.hour() == 18 || now.hour() == 0) {
- if (now.minute() == 0 && now.second() < 1) {
- digitalWrite(buzzer, HIGH);
- delay(250);
- digitalWrite(buzzer, LOW);
- delay(250);
- digitalWrite(buzzer, HIGH);
- delay(250);
- digitalWrite(buzzer, LOW);
- }
- }
- }
- void jamBesarMD() {
- DateTime now = rtc.now();
- String jamB, menit, detik;
- int jamRTC = now.hour();
- if (jamRTC <= 9) {
- jamB = "0" + String(jamRTC);
- } else {
- jamB = String(jamRTC);
- }
- int menitRTC = now.minute();
- if (menitRTC <= 9) {
- menit = "0" + String(menitRTC);
- } else {
- menit = String(menitRTC);
- }
- int detikRTC = now.second();
- if (detikRTC <= 9) {
- detik = "0" + String(detikRTC);
- } else {
- detik = String(detikRTC);
- }
- char jam[3];
- char mnt[3];
- char dtk[3];
- jamB.toCharArray(jam, 3);
- menit.toCharArray(mnt, 3);
- detik.toCharArray(dtk, 3);
- Disp.clear();
- Disp.setFont(Angka6x16);
- Disp.drawText(1, 0, jam);
- Disp.setFont(System6x7);
- Disp.drawText(18, -1, menit);
- Disp.drawText(18, 8, dtk);
- }
- void JadwalSholat() {
- DateTime now = rtc.now();
- int tglRTC = now.day();
- int blnRTC = now.month(); //Bulan
- int thnRTC = now.year(); //Tahun
- float lat = -0.7461316;
- float longs = 102.5184911;
- int zonawaktu = 7;
- set_calc_method(Karachi);
- set_asr_method(Shafii);
- set_high_lats_adjust_method(AngleBased);
- set_fajr_angle(20);
- set_isha_angle(18);
- get_prayer_times(thnRTC, blnRTC, tglRTC, lat, longs, zonawaktu, times);
- }
- void TampilJadwalSholat1() {
- JadwalSholat();
- static uint8_t i;
- char jam[5];
- char TimeName[][8] = { "SUBUH", "TERBIT", "DZUHUR", "ASHAR", "TRBNM", "MAGRIB", "ISYA" };
- int hours, minutes;
- if (i == 1) {
- i = 2; // Abaikan Terbit
- }
- if (i == 4) {
- i = 5; // Abaikan Terbenam
- }
- get_float_time_parts(times[i], hours, minutes);
- minutes = minutes + ihti;
- if (minutes >= 60) {
- minutes = minutes - 60;
- hours++;
- }
- String shalat = TimeName[i];
- sprintf(jam, "%02d:%02d", hours, minutes);
- Disp.clear();
- Disp.setFont(Font4x6);
- textCenterCustom(0, shalat);
- Disp.setFont(System6x7);
- textCenterCustom(8, jam);
- i++;
- if (i > 7) {
- get_float_time_parts(times[0], hours, minutes);
- minutes = minutes + ihti;
- if (minutes < 11) {
- minutes = 60 - minutes;
- hours--;
- } else {
- minutes = minutes - 10;
- }
- sprintf(jam, "%02d:%02d", hours, minutes);
- Disp.setFont(Font4x6);
- textCenterCustom(0, "IMSYAK");
- Disp.setFont(System6x7);
- textCenterCustom(8, jam);
- i = 0;
- tampil = 1;
- Disp.clear();
- }
- }
- /*Multi Task*/
- unsigned long previousMillis1 = 0;
- uint8_t u = 0;
- void loop() {
- // if (wifiMulti.run() == WL_CONNECTED) {
- //
- // }
- if (tampil == 1) {
- unsigned long currentMillis1 = millis();
- if ((unsigned long)(currentMillis1 - previousMillis1) >= 1000) {
- previousMillis1 = currentMillis1;
- jamBesarMD();
- beep();
- u++;
- if (u > 5) {
- tampil = 2;
- u = 0;
- }
- }
- } else if (tampil == 2) {
- hariTanggal();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement