#include <DHT.h>
#include <LedMatrix.h>
#define DHTPIN 15 // Use GPIO15 for DHT22 in Wokwi
#define DHTTYPE DHT22
#define DATA_IN 17 // Data in for LED Matrix
#define CLK_PIN 5 // Clock pin for LED Matrix
#define CS_PIN 4 // CS pin for LED Matrix
#define LDR_PIN 34 // Analog pin for LDR on ESP32
DHT dht(DHTPIN, DHTTYPE);
// Initialize LED matrix with LedMatrix library
LedMatrix ledMatrix = LedMatrix(DATA_IN, CLK_PIN, CS_PIN, 1, 4); // 1 row, 4 chained 8x8 displays
// Define weather condition patterns (8x8 binary arrays)
byte sunnyPattern[8] = {
B00011000, B00111100, B01111110, B11111111,
B01111110, B00111100, B00011000, B00000000
};
byte cloudyPattern[8] = {
B00000000, B00111000, B01111100, B11111110,
B01111111, B00111110, B00011100, B00000000
};
byte rainyPattern[8] = {
B00011000, B00111100, B01111110, B11111111,
B01111110, B00111100, B01001000, B10101000
};
byte stormyPattern[8] = {
B00011000, B00111100, B01111110, B11111111,
B01111110, B00111100, B01011000, B00010100
};
byte hotPattern[8] = {
B00011000, B00111100, B01111110, B11111111,
B11111111, B01111110, B00111100, B00011000
};
byte coldPattern[8] = {
B00000000, B01001010, B00111100, B00011000,
B00011000, B00111100, B01001010, B00000000
};
byte foggyPattern[8] = {
B00000000, B01111110, B11011011, B11111111,
B01111110, B11111111, B11011011, B00000000
};
byte overcastPattern[8] = {
B00000000, B00111000, B01111100, B11111110,
B01111111, B00111110, B00011100, B00000000
};
// Add the other patterns here...
// (cloudyPattern, rainyPattern, stormyPattern, hotPattern, coldPattern, foggyPattern, overcastPattern)
void setup() {
Serial.begin(9600);
dht.begin();
ledMatrix.init(); // Initialize the LED matrix
ledMatrix.setIntensity(8); // Set brightness level (0-15)
ledMatrix.clear(); // Clear display
}
void loop() {
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
int lightLevel = analogRead(LDR_PIN);
// Determine weather conditions and update LED panel
if (temperature > 30 && humidity < 40) {
displayWeather("HOT"); // Hot
} else if (temperature < 15 && humidity > 60) {
displayWeather("COLD"); // Cold
} else if (humidity > 90 && lightLevel < 100) {
displayWeather("FOGGY"); // Foggy
} else if (humidity > 70 && lightLevel < 100) {
displayWeather("STORMY"); // Stormy
} else if (humidity < 50 && temperature > 25) {
displayWeather("SUNNY"); // Sunny
} else if (humidity > 70 && lightLevel < 100) {
displayWeather("OVERCAST"); // Overcast
} else if (humidity > 60) {
displayWeather("RAINY"); // Rainy
} else {
displayWeather("CLOUDY"); // Default to cloudy
}
delay(2000);
}
void displayWeather(String condition) {
ledMatrix.clear();
// Select the pattern to display based on the weather condition
//byte* pattern = sunnyPattern; // Use a default pattern, e.g., sunnyPattern
if (condition == "COLD") {
pattern = coldPattern;
}
else if (condition == "HOT") {
pattern = hotPattern;
}
else if (condition == "CLOUDY") {
pattern = cloudyPattern;
}
else if (condition == "STORMY") {
pattern = stormyPattern;
}
else if (condition == "FOGGY") {
pattern = foggyPattern;
}
else if (condition == "OVERCAST") {
pattern = overcastPattern;
}
else if (condition == "RAINY") {
pattern = rainyPattern;
}
else {
pattern = sunnyPattern;
}
// Display the pattern across all matrices
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
bool pixel = bitRead(pattern[row], 7 - col); // Read each bit in the row
ledMatrix.setDot(col, row, pixel);
}
}
}