Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RTC_DS3231 rtc;
- char weekDay[][7] = { "AHAD", "SENIN", "SELASA", "RABU", "KAMIS", "JUM'AT", "SABTU", "AHAD" }; // array hari, dihitung mulai dari senin, hari senin angka nya =0,
- char monthYear[][4] = { "DES", "JAN", "FEB", "MAR", "APR", "MEI", "JUN", "JUL", "AGU", "SEP", "OKT", "NOV", "DES" };
- AsyncWebServer server(80);
- /******* Fonts *********/
- #include "fonts/angka.h"
- #include "fonts/angka_2.h"
- #include "fonts/angka_besar_kuru.h"
- #include "fonts/Angka6x16.h"
- #include "fonts/Arial_Black_16.h"
- #include "fonts/Arial_Black_16_ISO_8859_1.h"
- #include "fonts/Arial14.h"
- #include "fonts/ArialBlack10.h"
- #include "fonts/ArialBlack11.h"
- #include "fonts/baru.h"
- #include "fonts/Bernard16.h"
- #include "fonts/BigNumber.h"
- #include "fonts/BodoniBlack16.h"
- #include "fonts/BritanicBold11.h"
- #include "fonts/Brodway15.h"
- #include "fonts/CooperBlack16.h"
- #include "fonts/DejaVuSans9.h"
- #include "fonts/DejaVuSansBold9.h"
- #include "fonts/DejaVuSansItalic9.h"
- #include "fonts/Droid_Sans_12.h"
- #include "fonts/Droid_Sans_16.h"
- #include "fonts/Droid_Sans_24.h"
- #include "fonts/ElektronMart5x6.h"
- #include "fonts/ElektronMart6x8.h"
- #include "fonts/ElektronMart6x12.h"
- #include "fonts/ElektronMart6x16.h"
- #include "fonts/ElektronMartArabic3x6.h"
- #include "fonts/ElektronMartArabic5x6.h"
- #include "fonts/ElektronMartArabic6x16.h"
- #include "fonts/EMKotak5x7.h"
- #include "fonts/EMSans5x6.h"
- #include "fonts/EMSans6x8.h"
- #include "fonts/EMSans6x16.h"
- #include "fonts/EMSans8x16.h"
- #include "fonts/FIXEDNUMS7x15.h"
- #include "fonts/FONT_7x6.h"
- #include "fonts/Font3x5.h"
- #include "fonts/Font4x6.h"
- #include "fonts/Font5x6.h"
- #include "fonts/Mono5x7.h"
- #include "fonts/MyBigFont.h"
- #include "fonts/Small4x6.h"
- #include "fonts/SmallCap4x6.h"
- #include "fonts/Stencil12.h"
- #include "fonts/System6x7.h"
- #include "fonts/SystemFont3x5.h"
- #include "fonts/SystemFont5x7.h"
- #include "fonts/Tahoma.h"
- #include "fonts/TimesNewRoman10.h"
- #include "fonts/TimesNewRoman12.h"
- /****** END FOnts *****/
- double times[sizeof(TimeName) / sizeof(char*)];
- int ihti = 2;
- String ssidAP;
- String passAP;
- String ssid;
- String pass;
- String ip;
- String gateway;
- String id_device;
- String waktu;
- String kecerahan;
- String latitudeS;
- String longitudeS;
- String state_wifi;
- String setting;
- String subnetMask;
- byte tgl, bln, thn, jam, mnt, dtk;
- bool wifiNotConneccted = false;
- IPAddress localIP;
- //IPAddress localIP(192, 168, 1, 200); // hardcoded
- // Set your Gateway IP address
- IPAddress localGateway;
- //IPAddress localGateway(192, 168, 1, 1); //hardcoded
- IPAddress localSubnet;
- /********** Display *********/
- // SETUP DMD HJS589
- #define DISPLAYS_WIDE 1
- #define DISPLAYS_HIGH 1
- HJS589 Disp(DISPLAYS_WIDE, DISPLAYS_HIGH); // Jumlah Panel P10 yang digunakan (KOLOM,BARIS)
- //----------------------------------------------------------------------
- // HJS589 P10 FUNGSI TAMBAHAN UNTUK NODEMCU ESP8266
- void ICACHE_RAM_ATTR refresh() {
- Disp.refresh();
- timer0_write(ESP.getCycleCount() + 80000);
- }
- void Disp_init() {
- Disp.start();
- noInterrupts();
- timer0_isr_init();
- timer0_attachInterrupt(refresh);
- Disp.clear();
- }
- /********** END Display *********/
- void notFound(AsyncWebServerRequest* request) {
- // request->send(404, "text/plain", "Not found");
- request->redirect("/");
- }
- /********************* WiFI *********************/
- bool initWiFi() {
- if (ssid == "" || ip == "") {
- Serial.println("Undefined SSID or IP address.");
- return false;
- }
- WiFi.mode(WIFI_STA);
- /*WiFi STA*
- localIP.fromString(ip.c_str());
- localGateway.fromString(gateway.c_str());
- localSubnet.fromString(subnetMask.c_str());
- WiFi.hostname("jam Digital By Sebuahhobi");
- if (!WiFi.config(localIP, localGateway, localSubnet)) {
- Serial.println("STA Failed to configure");
- return false;
- }
- /*END WiFi STA*/
- WiFi.hostname("jam Digital");
- wifiMulti.addAP("SSID JWS", "passwordnyapaaja");
- Serial.println("Connecting to WiFi...");
- if (wifiMulti.run() == WL_CONNECTED) {
- Serial.println("");
- Serial.println("WiFi connected");
- Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- }
- return true;
- }
- void hotspot() {
- WiFi.softAP(ssidAP.c_str(), passAP.c_str());
- WiFi.hostname("jam Digital");
- IPAddress IP = WiFi.softAPIP();
- Serial.print("AP IP address: ");
- Serial.println(IP);
- }
- /********************* END WiFI *********************/
- /********************* LittleFS *********************/
- void initSPIFFS() {
- if (!LittleFS.begin()) {
- Serial.println("An Error has occurred while mounting LittleFS");
- return;
- }
- Serial.println("SPIFFS mounted successfully");
- }
- int I2C_ClearBus() {
- #if defined(TWCR) && defined(TWEN)
- TWCR &= ~(_BV(TWEN)); //Disable the Atmel 2-Wire interface so we can control the SDA and SCL pins directly
- #endif
- pinMode(SDA, INPUT_PULLUP); // Make SDA (data) and SCL (clock) pins Inputs with pullup.
- pinMode(SCL, INPUT_PULLUP);
- delay(2500); // Wait 2.5 secs. This is strictly only necessary on the first power
- // up of the DS3231 module to allow it to initialize properly,
- // but is also assists in reliable programming of FioV3 boards as it gives the
- // IDE a chance to start uploaded the program
- // before existing sketch confuses the IDE by sending Serial data.
- boolean SCL_LOW = (digitalRead(SCL) == LOW); // Check is SCL is Low.
- if (SCL_LOW) { //If it is held low Arduno cannot become the I2C master.
- return 1; //I2C bus error. Could not clear SCL clock line held low
- }
- boolean SDA_LOW = (digitalRead(SDA) == LOW); // vi. Check SDA input.
- int clockCount = 20; // > 2x9 clock
- while (SDA_LOW && (clockCount > 0)) { // vii. If SDA is Low,
- clockCount--;
- // Note: I2C bus is open collector so do NOT drive SCL or SDA high.
- pinMode(SCL, INPUT); // release SCL pullup so that when made output it will be LOW
- pinMode(SCL, OUTPUT); // then clock SCL Low
- delayMicroseconds(10); // for >5uS
- pinMode(SCL, INPUT); // release SCL LOW
- pinMode(SCL, INPUT_PULLUP); // turn on pullup resistors again
- // do not force high as slave may be holding it low for clock stretching.
- delayMicroseconds(10); // for >5uS
- // The >5uS is so that even the slowest I2C devices are handled.
- SCL_LOW = (digitalRead(SCL) == LOW); // Check if SCL is Low.
- int counter = 20;
- while (SCL_LOW && (counter > 0)) { // loop waiting for SCL to become High only wait 2sec.
- counter--;
- delay(100);
- SCL_LOW = (digitalRead(SCL) == LOW);
- }
- if (SCL_LOW) { // still low after 2 sec error
- return 2; // I2C bus error. Could not clear. SCL clock line held low by slave clock stretch for >2sec
- }
- SDA_LOW = (digitalRead(SDA) == LOW); // and check SDA input again and loop
- }
- if (SDA_LOW) { // still low
- return 3; // I2C bus error. Could not clear. SDA data line held low
- }
- // else pull SDA line low for Start or Repeated Start
- pinMode(SDA, INPUT); // remove pullup.
- pinMode(SDA, OUTPUT); // and then make it LOW i.e. send an I2C Start or Repeated start control.
- // When there is only one I2C master a Start or Repeat Start has the same function as a Stop and clears the bus.
- /// A Repeat Start is a Start occurring after a Start with no intervening Stop.
- delayMicroseconds(10); // wait >5uS
- pinMode(SDA, INPUT); // remove output low
- pinMode(SDA, INPUT_PULLUP); // and make SDA high i.e. send I2C STOP control.
- delayMicroseconds(10); // x. wait >5uS
- pinMode(SDA, INPUT); // and reset pins as tri-state inputs which is the default state on reset
- pinMode(SCL, INPUT);
- return 0; // all ok
- }
Add Comment
Please, Sign In to add comment