Sebuahhobi98

setting.h

Aug 29th, 2022
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. RTC_DS3231 rtc;
  2. char weekDay[][7] = { "AHAD", "SENIN", "SELASA", "RABU", "KAMIS", "JUM'AT", "SABTU", "AHAD" };  // array hari, dihitung mulai dari senin, hari senin angka nya =0,
  3. char monthYear[][4] = { "DES", "JAN", "FEB", "MAR", "APR", "MEI", "JUN", "JUL", "AGU", "SEP", "OKT", "NOV", "DES" };
  4.  
  5. AsyncWebServer server(80);
  6.  
  7. /******* Fonts  *********/
  8. #include "fonts/angka.h"
  9. #include "fonts/angka_2.h"
  10. #include "fonts/angka_besar_kuru.h"
  11. #include "fonts/Angka6x16.h"
  12. #include "fonts/Arial_Black_16.h"
  13. #include "fonts/Arial_Black_16_ISO_8859_1.h"
  14. #include "fonts/Arial14.h"
  15. #include "fonts/ArialBlack10.h"
  16. #include "fonts/ArialBlack11.h"
  17. #include "fonts/baru.h"
  18. #include "fonts/Bernard16.h"
  19. #include "fonts/BigNumber.h"
  20. #include "fonts/BodoniBlack16.h"
  21. #include "fonts/BritanicBold11.h"
  22. #include "fonts/Brodway15.h"
  23. #include "fonts/CooperBlack16.h"
  24. #include "fonts/DejaVuSans9.h"
  25. #include "fonts/DejaVuSansBold9.h"
  26. #include "fonts/DejaVuSansItalic9.h"
  27. #include "fonts/Droid_Sans_12.h"
  28. #include "fonts/Droid_Sans_16.h"
  29. #include "fonts/Droid_Sans_24.h"
  30. #include "fonts/ElektronMart5x6.h"
  31. #include "fonts/ElektronMart6x8.h"
  32. #include "fonts/ElektronMart6x12.h"
  33. #include "fonts/ElektronMart6x16.h"
  34. #include "fonts/ElektronMartArabic3x6.h"
  35. #include "fonts/ElektronMartArabic5x6.h"
  36. #include "fonts/ElektronMartArabic6x16.h"
  37. #include "fonts/EMKotak5x7.h"
  38. #include "fonts/EMSans5x6.h"
  39. #include "fonts/EMSans6x8.h"
  40. #include "fonts/EMSans6x16.h"
  41. #include "fonts/EMSans8x16.h"
  42. #include "fonts/FIXEDNUMS7x15.h"
  43. #include "fonts/FONT_7x6.h"
  44. #include "fonts/Font3x5.h"
  45. #include "fonts/Font4x6.h"
  46. #include "fonts/Font5x6.h"
  47. #include "fonts/Mono5x7.h"
  48. #include "fonts/MyBigFont.h"
  49. #include "fonts/Small4x6.h"
  50. #include "fonts/SmallCap4x6.h"
  51. #include "fonts/Stencil12.h"
  52. #include "fonts/System6x7.h"
  53. #include "fonts/SystemFont3x5.h"
  54. #include "fonts/SystemFont5x7.h"
  55. #include "fonts/Tahoma.h"
  56. #include "fonts/TimesNewRoman10.h"
  57. #include "fonts/TimesNewRoman12.h"
  58. /****** END FOnts *****/
  59.  
  60.  
  61. double times[sizeof(TimeName) / sizeof(char*)];
  62. int ihti = 2;
  63.  
  64. String ssidAP;
  65. String passAP;
  66.  
  67. String ssid;
  68. String pass;
  69. String ip;
  70. String gateway;
  71. String id_device;
  72. String waktu;
  73. String kecerahan;
  74. String latitudeS;
  75. String longitudeS;
  76. String state_wifi;
  77. String setting;
  78. String subnetMask;
  79. byte tgl, bln, thn, jam, mnt, dtk;
  80. bool wifiNotConneccted = false;
  81.  
  82. IPAddress localIP;
  83. //IPAddress localIP(192, 168, 1, 200); // hardcoded
  84.  
  85. // Set your Gateway IP address
  86. IPAddress localGateway;
  87. //IPAddress localGateway(192, 168, 1, 1); //hardcoded
  88. IPAddress localSubnet;
  89.  
  90.  
  91. /********** Display *********/
  92. // SETUP DMD HJS589
  93.  
  94. #define DISPLAYS_WIDE 1
  95. #define DISPLAYS_HIGH 1
  96. HJS589 Disp(DISPLAYS_WIDE, DISPLAYS_HIGH);  // Jumlah Panel P10 yang digunakan (KOLOM,BARIS)
  97.  
  98. //----------------------------------------------------------------------
  99. // HJS589 P10 FUNGSI TAMBAHAN UNTUK NODEMCU ESP8266
  100. void ICACHE_RAM_ATTR refresh() {
  101.   Disp.refresh();
  102.   timer0_write(ESP.getCycleCount() + 80000);
  103. }
  104.  
  105. void Disp_init() {
  106.   Disp.start();
  107.   noInterrupts();
  108.   timer0_isr_init();
  109.   timer0_attachInterrupt(refresh);
  110.   Disp.clear();
  111. }
  112.  
  113. /********** END Display *********/
  114.  
  115.  
  116. void notFound(AsyncWebServerRequest* request) {
  117.   //  request->send(404, "text/plain", "Not found");
  118.   request->redirect("/");
  119. }
  120.  
  121. /********************* WiFI *********************/
  122. bool initWiFi() {
  123.   if (ssid == "" || ip == "") {
  124.     Serial.println("Undefined SSID or IP address.");
  125.     return false;
  126.   }
  127.   WiFi.mode(WIFI_STA);
  128.   /*WiFi STA*
  129.     localIP.fromString(ip.c_str());
  130.     localGateway.fromString(gateway.c_str());
  131.     localSubnet.fromString(subnetMask.c_str());
  132.     WiFi.hostname("jam Digital By Sebuahhobi");
  133.  
  134.     if (!WiFi.config(localIP, localGateway, localSubnet)) {
  135.  
  136.     Serial.println("STA Failed to configure");
  137.     return false;
  138.     }
  139.  
  140.     /*END WiFi STA*/
  141.   WiFi.hostname("jam Digital");
  142.   wifiMulti.addAP("SSID JWS", "passwordnyapaaja");
  143.  
  144.   Serial.println("Connecting to WiFi...");
  145.  
  146.   if (wifiMulti.run() == WL_CONNECTED) {
  147.     Serial.println("");
  148.     Serial.println("WiFi connected");
  149.     Serial.println("IP address: ");
  150.     Serial.println(WiFi.localIP());
  151.   }
  152.  
  153.   return true;
  154. }
  155. void hotspot() {
  156.   WiFi.softAP(ssidAP.c_str(), passAP.c_str());
  157.   WiFi.hostname("jam Digital");
  158.   IPAddress IP = WiFi.softAPIP();
  159.   Serial.print("AP IP address: ");
  160.   Serial.println(IP);
  161. }
  162.  
  163. /********************* END WiFI *********************/
  164.  
  165. /********************* LittleFS *********************/
  166.  
  167. void initSPIFFS() {
  168.   if (!LittleFS.begin()) {
  169.     Serial.println("An Error has occurred while mounting LittleFS");
  170.     return;
  171.   }
  172.   Serial.println("SPIFFS mounted successfully");
  173. }
  174.  
  175. int I2C_ClearBus() {
  176. #if defined(TWCR) && defined(TWEN)
  177.   TWCR &= ~(_BV(TWEN));  //Disable the Atmel 2-Wire interface so we can control the SDA and SCL pins directly
  178. #endif
  179.  
  180.   pinMode(SDA, INPUT_PULLUP);  // Make SDA (data) and SCL (clock) pins Inputs with pullup.
  181.   pinMode(SCL, INPUT_PULLUP);
  182.  
  183.   delay(2500);  // Wait 2.5 secs. This is strictly only necessary on the first power
  184.   // up of the DS3231 module to allow it to initialize properly,
  185.   // but is also assists in reliable programming of FioV3 boards as it gives the
  186.   // IDE a chance to start uploaded the program
  187.   // before existing sketch confuses the IDE by sending Serial data.
  188.  
  189.   boolean SCL_LOW = (digitalRead(SCL) == LOW);  // Check is SCL is Low.
  190.   if (SCL_LOW) {                                //If it is held low Arduno cannot become the I2C master.
  191.     return 1;                                   //I2C bus error. Could not clear SCL clock line held low
  192.   }
  193.  
  194.   boolean SDA_LOW = (digitalRead(SDA) == LOW);  // vi. Check SDA input.
  195.   int clockCount = 20;                          // > 2x9 clock
  196.  
  197.   while (SDA_LOW && (clockCount > 0)) {  //  vii. If SDA is Low,
  198.     clockCount--;
  199.     // Note: I2C bus is open collector so do NOT drive SCL or SDA high.
  200.     pinMode(SCL, INPUT);         // release SCL pullup so that when made output it will be LOW
  201.     pinMode(SCL, OUTPUT);        // then clock SCL Low
  202.     delayMicroseconds(10);       //  for >5uS
  203.     pinMode(SCL, INPUT);         // release SCL LOW
  204.     pinMode(SCL, INPUT_PULLUP);  // turn on pullup resistors again
  205.     // do not force high as slave may be holding it low for clock stretching.
  206.     delayMicroseconds(10);  //  for >5uS
  207.     // The >5uS is so that even the slowest I2C devices are handled.
  208.     SCL_LOW = (digitalRead(SCL) == LOW);  // Check if SCL is Low.
  209.     int counter = 20;
  210.     while (SCL_LOW && (counter > 0)) {  //  loop waiting for SCL to become High only wait 2sec.
  211.       counter--;
  212.       delay(100);
  213.       SCL_LOW = (digitalRead(SCL) == LOW);
  214.     }
  215.     if (SCL_LOW) {  // still low after 2 sec error
  216.       return 2;     // I2C bus error. Could not clear. SCL clock line held low by slave clock stretch for >2sec
  217.     }
  218.     SDA_LOW = (digitalRead(SDA) == LOW);  //   and check SDA input again and loop
  219.   }
  220.   if (SDA_LOW) {  // still low
  221.     return 3;     // I2C bus error. Could not clear. SDA data line held low
  222.   }
  223.  
  224.   // else pull SDA line low for Start or Repeated Start
  225.   pinMode(SDA, INPUT);   // remove pullup.
  226.   pinMode(SDA, OUTPUT);  // and then make it LOW i.e. send an I2C Start or Repeated start control.
  227.   // When there is only one I2C master a Start or Repeat Start has the same function as a Stop and clears the bus.
  228.   /// A Repeat Start is a Start occurring after a Start with no intervening Stop.
  229.   delayMicroseconds(10);       // wait >5uS
  230.   pinMode(SDA, INPUT);         // remove output low
  231.   pinMode(SDA, INPUT_PULLUP);  // and make SDA high i.e. send I2C STOP control.
  232.   delayMicroseconds(10);       // x. wait >5uS
  233.   pinMode(SDA, INPUT);         // and reset pins as tri-state inputs which is the default state on reset
  234.   pinMode(SCL, INPUT);
  235.   return 0;  // all ok
  236. }
Add Comment
Please, Sign In to add comment