Advertisement
Sebuahhobi98

jws.ino

Aug 29th, 2022
1,329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ESP8266WiFi.h>
  2. #include <ESPAsyncTCP.h>
  3. #include <ESP8266WiFiMulti.h>
  4. ESP8266WiFiMulti wifiMulti;
  5.  
  6. #include <ESPAsyncWebServer.h>
  7. #include <ArduinoJson.h>
  8. #include <Wire.h>
  9. #include <RTClib.h>
  10. #include "PrayerTimes.h"
  11. #include "HJS589.h"
  12. #include <LittleFS.h>
  13. #include "setting.h"
  14.  
  15. const int buzzer = 15;  // Pin GPIO Buzzer - D4
  16.  
  17. void wifi() {
  18.   server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
  19.     request->send(LittleFS, "/setting.html", "text/html");
  20.   });
  21.  
  22.   server.serveStatic("/", LittleFS, "/");
  23.  
  24.   server.onNotFound(notFound);
  25.   server.begin();
  26.   Serial.println("Server begin");
  27.   Serial.println();
  28. }
  29.  
  30. uint8_t tampil = 1;
  31. #define buzzer 3
  32. void setup() {
  33.   Serial.begin(115200);
  34.  
  35.   initSPIFFS();
  36.   readSetting();
  37.  
  38.   if (doc["state_wifi"].as<String>() == "true") {
  39.     Serial.println("State Wifi: true");
  40.     if (!initWiFi()) {
  41.       hotspot();
  42.     }
  43.   } else if (doc["state_wifi"] == "false") {
  44.     Serial.println("State Wifi: false");
  45.     hotspot();
  46.   }
  47.  
  48.   Disp_init();
  49.   Disp.setBrightness(50);
  50.   Serial.println("Display init");
  51.   Serial.println();
  52.  
  53.   while (!rtc.begin()) {
  54.     Serial.println("Clear I2C");
  55.     I2C_ClearBus();
  56.     delay(250);
  57.     if (!rtc.begin()) {
  58.       Serial.println("Couldn't find RTC");
  59.       //while (1);
  60.     }
  61.   }
  62.  
  63.   wifi();
  64.  
  65.   //Buzzer
  66.   pinMode(buzzer, OUTPUT);
  67. }
  68.  
  69. void beep() {
  70.   DateTime now = rtc.now();
  71.   if (now.minute() == 0 && now.hour() != 12 && now.hour() != 0 && now.hour() != 6 && now.hour() != 18 && now.second() < 1) {
  72.     digitalWrite(buzzer, HIGH);
  73.     delay(250);
  74.     digitalWrite(buzzer, LOW);
  75.   }
  76.  
  77.   if (now.hour() == 6 || now.hour() == 12 || now.hour() == 18 || now.hour() == 0) {
  78.     if (now.minute() == 0 && now.second() < 1) {
  79.       digitalWrite(buzzer, HIGH);
  80.       delay(250);
  81.       digitalWrite(buzzer, LOW);
  82.       delay(250);
  83.       digitalWrite(buzzer, HIGH);
  84.       delay(250);
  85.       digitalWrite(buzzer, LOW);
  86.     }
  87.   }
  88. }
  89.  
  90. void jamBesarMD() {
  91.   DateTime now = rtc.now();
  92.   String jamB, menit, detik;
  93.   int jamRTC = now.hour();
  94.   if (jamRTC <= 9) {
  95.     jamB = "0" + String(jamRTC);
  96.   } else {
  97.     jamB = String(jamRTC);
  98.   }
  99.   int menitRTC = now.minute();
  100.   if (menitRTC <= 9) {
  101.     menit = "0" + String(menitRTC);
  102.   } else {
  103.     menit = String(menitRTC);
  104.   }
  105.   int detikRTC = now.second();
  106.   if (detikRTC <= 9) {
  107.     detik = "0" + String(detikRTC);
  108.   } else {
  109.     detik = String(detikRTC);
  110.   }
  111.  
  112.   char jam[3];
  113.   char mnt[3];
  114.   char dtk[3];
  115.  
  116.   jamB.toCharArray(jam, 3);
  117.   menit.toCharArray(mnt, 3);
  118.   detik.toCharArray(dtk, 3);
  119.   Disp.clear();
  120.   Disp.setFont(Angka6x16);
  121.   Disp.drawText(1, 0, jam);
  122.  
  123.   Disp.setFont(System6x7);
  124.   Disp.drawText(18, -1, menit);
  125.   Disp.drawText(18, 8, dtk);
  126. }
  127.  
  128. void JadwalSholat() {
  129.   DateTime now = rtc.now();
  130.   int tglRTC = now.day();
  131.   int blnRTC = now.month();  //Bulan
  132.   int thnRTC = now.year();   //Tahun
  133.   float lat = -0.7461316;
  134.   float longs = 102.5184911;
  135.   int zonawaktu = 7;
  136.  
  137.   set_calc_method(Karachi);
  138.   set_asr_method(Shafii);
  139.   set_high_lats_adjust_method(AngleBased);
  140.   set_fajr_angle(20);
  141.   set_isha_angle(18);
  142.  
  143.   get_prayer_times(thnRTC, blnRTC, tglRTC, lat, longs, zonawaktu, times);
  144. }
  145.  
  146. void TampilJadwalSholat1() {
  147.   JadwalSholat();
  148.   static uint8_t i;
  149.   char jam[5];
  150.   char TimeName[][8] = { "SUBUH", "TERBIT", "DZUHUR", "ASHAR", "TRBNM", "MAGRIB", "ISYA" };
  151.   int hours, minutes;
  152.   if (i == 1) {
  153.     i = 2;  // Abaikan Terbit
  154.   }
  155.   if (i == 4) {
  156.     i = 5;  // Abaikan Terbenam
  157.   }
  158.  
  159.   get_float_time_parts(times[i], hours, minutes);
  160.  
  161.   minutes = minutes + ihti;
  162.  
  163.   if (minutes >= 60) {
  164.     minutes = minutes - 60;
  165.     hours++;
  166.   }
  167.  
  168.   String shalat = TimeName[i];
  169.   sprintf(jam, "%02d:%02d", hours, minutes);
  170.   Disp.clear();
  171.   Disp.setFont(Font4x6);
  172.   textCenterCustom(0, shalat);
  173.   Disp.setFont(System6x7);
  174.   textCenterCustom(8, jam);
  175.  
  176.   i++;
  177.  
  178.   if (i > 7) {
  179.     get_float_time_parts(times[0], hours, minutes);
  180.     minutes = minutes + ihti;
  181.     if (minutes < 11) {
  182.       minutes = 60 - minutes;
  183.       hours--;
  184.     } else {
  185.       minutes = minutes - 10;
  186.     }
  187.     sprintf(jam, "%02d:%02d", hours, minutes);
  188.     Disp.setFont(Font4x6);
  189.     textCenterCustom(0, "IMSYAK");
  190.     Disp.setFont(System6x7);
  191.     textCenterCustom(8, jam);
  192.     i = 0;
  193.     tampil = 1;
  194.     Disp.clear();
  195.   }
  196. }
  197.  
  198.  
  199. /*Multi Task*/
  200. unsigned long previousMillis1 = 0;
  201. uint8_t u = 0;
  202. void loop() {
  203. //  if (wifiMulti.run() == WL_CONNECTED) {
  204. //    
  205. //  }
  206.   if (tampil == 1) {
  207.     unsigned long currentMillis1 = millis();
  208.     if ((unsigned long)(currentMillis1 - previousMillis1) >= 1000) {
  209.       previousMillis1 = currentMillis1;
  210.       jamBesarMD();
  211.       beep();
  212.       u++;
  213.       if (u > 5) {
  214.         tampil = 2;
  215.         u = 0;
  216.       }
  217.     }
  218.   } else if (tampil == 2) {
  219.     hariTanggal();
  220.   }
  221. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement