/* Rui Santos Complete project details at https://RandomNerdTutorials.com/esp32-weather-station-pcb/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. */ #include #include #include #include #include #include #include #include #include // Insert your network credentials const char* ssid = "REPLACE_WITH_YOUR_SSID"; const char* password = "REPLACE_WITH_YOUR_PASSWORD"; // NTP Server Details const char* ntpServer = "pool.ntp.org"; const long gmtOffset_sec = 0; const int daylightOffset_sec = 3600; // OLED Display #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define I2Cdisplay_SDA 21 #define I2Cdisplay_SCL 22 TwoWire I2Cdisplay = TwoWire(1); Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &I2Cdisplay, -1); // WS2812B Addressable RGB LEDs #define LED_PIN 27 // GPIO the LEDs are connected to #define LED_COUNT 12 // Number of LEDs Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); // BME280 #define I2C_SDA 21 #define I2C_SCL 22 TwoWire I2CBME = TwoWire(0); Adafruit_BME280 bme; // LDR (Light Dependent Resistor) #define ldr 33 // Pushbutton #define buttonPin 18 int buttonState; // current reading from the input pin int lastButtonState = LOW; // previous reading from the input pin unsigned long lastDebounceTime = 0; // the last time the output pin was toggled unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers // Screens int displayScreenNum = 0; int displayScreenNumMax = 4; unsigned long lastTimer = 0; unsigned long timerDelay = 15000; unsigned char temperature_icon[] ={ 0b00000001, 0b11000000, // ### 0b00000011, 0b11100000, // ##### 0b00000111, 0b00100000, // ### # 0b00000111, 0b11100000, // ###### 0b00000111, 0b00100000, // ### # 0b00000111, 0b11100000, // ###### 0b00000111, 0b00100000, // ### # 0b00000111, 0b11100000, // ###### 0b00000111, 0b00100000, // ### # 0b00001111, 0b11110000, // ######## 0b00011111, 0b11111000, // ########## 0b00011111, 0b11111000, // ########## 0b00011111, 0b11111000, // ########## 0b00011111, 0b11111000, // ########## 0b00001111, 0b11110000, // ######## 0b00000111, 0b11100000, // ###### }; unsigned char humidity_icon[] ={ 0b00000000, 0b00000000, // 0b00000001, 0b10000000, // ## 0b00000011, 0b11000000, // #### 0b00000111, 0b11100000, // ###### 0b00001111, 0b11110000, // ######## 0b00001111, 0b11110000, // ######## 0b00011111, 0b11111000, // ########## 0b00011111, 0b11011000, // ####### ## 0b00111111, 0b10011100, // ####### ### 0b00111111, 0b10011100, // ####### ### 0b00111111, 0b00011100, // ###### ### 0b00011110, 0b00111000, // #### ### 0b00011111, 0b11111000, // ########## 0b00001111, 0b11110000, // ######## 0b00000011, 0b11000000, // #### 0b00000000, 0b00000000, // }; unsigned char arrow_down_icon[] ={ 0b00001111, 0b11110000, // ######## 0b00011111, 0b11111000, // ########## 0b00011111, 0b11111000, // ########## 0b00011100, 0b00111000, // ### ### 0b00011100, 0b00111000, // ### ### 0b00011100, 0b00111000, // ### ### 0b01111100, 0b00111110, // ##### ##### 0b11111100, 0b00111111, // ###### ###### 0b11111100, 0b00111111, // ###### ###### 0b01111000, 0b00011110, // #### #### 0b00111100, 0b00111100, // #### #### 0b00011110, 0b01111000, // #### #### 0b00001111, 0b11110000, // ######## 0b00000111, 0b11100000, // ###### 0b00000011, 0b11000000, // #### 0b00000001, 0b10000000, // ## }; unsigned char sun_icon[] ={ 0b00000000, 0b00000000, // 0b00100000, 0b10000010, // # # # 0b00010000, 0b10000100, // # # # 0b00001000, 0b00001000, // # # 0b00000001, 0b11000000, // ### 0b00000111, 0b11110000, // ####### 0b00000111, 0b11110000, // ####### 0b00001111, 0b11111000, // ######### 0b01101111, 0b11111011, // ## ######### ## 0b00001111, 0b11111000, // ######### 0b00000111, 0b11110000, // ####### 0b00000111, 0b11110000, // ####### 0b00010001, 0b11000100, // # ### # 0b00100000, 0b00000010, // # # 0b01000000, 0b10000001, // # # # 0b00000000, 0b10000000, // # }; // Clear the LEDs void colorWipe(uint32_t color, int wait, int numNeoPixels) { for(int i=0; i debounceDelay) { if (reading != buttonState) { buttonState = reading; if (buttonState == HIGH) { updateScreen(); Serial.println(displayScreenNum); if(displayScreenNum < displayScreenNumMax) { displayScreenNum++; } else { displayScreenNum = 0; } lastTimer = millis(); } } } lastButtonState = reading; // Change screen every 15 seconds (timerDelay variable) if ((millis() - lastTimer) > timerDelay) { updateScreen(); Serial.println(displayScreenNum); if(displayScreenNum < displayScreenNumMax) { displayScreenNum++; } else { displayScreenNum = 0; } lastTimer = millis(); } }