#include #include #include #include #include #include #include #include #include struct Button { const uint8_t PIN; uint32_t numberKeyPresses; bool pressed; }; Button button1 = {D6, 0, false}; unsigned long previousMillis = 0; // will store last time was updated // constants won't change: const long interval = 10000; // interval at which to delay (milliseconds) //variables to keep track of the timing of recent interrupts unsigned long button_time = 0; unsigned long last_button_time = 0; void ICACHE_RAM_ATTR isr() { button_time = millis(); if (button_time - last_button_time > 250) { button1.numberKeyPresses++; button1.pressed = true; last_button_time = button_time; } } // Replace with your network credentials const char* ssid = "user"; const char* password = "pass"; // Define NTP Client to get time WiFiUDP ntpUDP; NTPClient timeClient(ntpUDP, "pool.ntp.org"); //BME #define SEALEVELPRESSURE_HPA (1013.25) Adafruit_BME280 bme; float temperature, humidity, pressure, altitude; float mintemperature, minpressure, maxtemperature, maxpressure ; //OLED #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); void setup() { Serial.begin(115200); delay(1000); Serial.println("SERIAL OK"); //Interrupt pinMode(button1.PIN, INPUT_PULLUP); attachInterrupt(button1.PIN, isr, FALLING); // Connect to Wi-Fi Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } // Initialize a NTPClient to get time timeClient.begin(); // Set offset time in seconds to adjust for your timezone, for example: // GMT +1 = 3600 // GMT +8 = 28800 // GMT -1 = -3600 // GMT 0 = 0 timeClient.setTimeOffset(7200); // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { Serial.println(F("SSD1306 allocation failed")); for(;;); // Don't proceed, loop forever } bme.begin(0x76); display.display(); delay(2000); // Pause for 2 seconds mintemperature = bme.readTemperature(); minpressure = bme.readPressure() / 100.0F + 21; maxtemperature = mintemperature; maxpressure = minpressure; } void loop() { if (button1.pressed) { Serial.printf("Button has been pressed %u times\n", button1.numberKeyPresses); button1.pressed = false; display.clearDisplay(); display.setTextSize(1); // Normal 1:1 pixel scale display.setTextColor(SSD1306_WHITE); // Draw white text display.setCursor(0, 0); // Start at top-left corner display.cp437(true); // Use full 256 char 'Code Page 437' font display.println("MINISTANICE PHRUB"); display.println("-----------------"); display.print("Min. teplota: "); display.println(mintemperature); display.print("Max. teplota: "); display.println(maxtemperature); display.print("Min. tlak: "); display.println(minpressure); display.print("Max. tlak: "); display.println(maxpressure); display.println("-----------------"); display.display(); delay(1000); } unsigned long currentMillis = millis(); if (currentMillis - previousMillis >= interval) { // save the last time you blinked the LED previousMillis = currentMillis; timeClient.update(); String formattedTime = timeClient.getFormattedTime(); time_t epochTime = timeClient.getEpochTime(); //Serial.print("Epoch Time: "); //Serial.println(epochTime); //Get a time structure struct tm *ptm = gmtime ((time_t *)&epochTime); int monthDay = ptm->tm_mday; int currentMonth = ptm->tm_mon+1; int letCas= ptm->tm_isdst; //Serial.print("Letni cas: "); //Serial.println(letCas); //String currentMonthName = months[currentMonth-1]; //Serial.print("Month name: "); //Serial.println(currentMonthName); int currentYear = ptm->tm_year+1900; //Print complete date: String currentDate = String(currentYear) + "-" + String(currentMonth) + "-" + String(monthDay); Serial.print("Current date: "); Serial.println(currentDate); temperature = bme.readTemperature(); humidity = bme.readHumidity(); pressure = bme.readPressure() / 100.0F + 21; if (mintemperature>temperature){mintemperature = temperature;} if (maxtemperaturepressure){minpressure = pressure;} if (maxpressure