#include <LiquidCrystal.h>
// Define the LCD pin connections
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// Constants for shading types and time frame ranges
const float timeFrames[] = {0.0, 0.6, 1.2, 1.8, 2.4, 3.0};
const char* shadingTypes[] = {"Bottom Shading", "L-Shaped Shading", "Corner Shading", "Center Shading", "Side Shading"};
// Updated irradiance matrix from the provided table (row, column, time)
float irradiance[5][5][6] = {
{{800, 100, 100, 800, 800}, {800, 800, 400, 800, 800}, {800, 800, 800, 800, 800}, {800, 800, 800, 800, 800}},
{{800, 400, 400, 800, 800}, {800, 800, 100, 100, 800}, {800, 800, 800, 400, 800}, {800, 800, 800, 800, 400}},
{{800, 100, 100, 800, 800}, {800, 800, 400, 400, 800}, {800, 800, 800, 100, 800}, {800, 800, 800, 800, 100}},
{{800, 400, 800, 800, 800}, {800, 800, 800, 100, 800}, {800, 800, 800, 400, 800}, {800, 800, 800, 800, 400}},
{{100, 100, 800, 800, 800}, {400, 400, 800, 800, 800}, {100, 100, 800, 800, 800}, {400, 400, 800, 800, 100}}
};
// Function to get user input and shading type
void askUserInput(float &startTime, float &endTime) {
Serial.println("Enter the start time of the time frame:");
startTime = getUserInput("Start Time (0.0, 0.6, 1.2, 1.8, 2.4): ", 0.0, 2.4);
Serial.println("Enter the end time of the time frame:");
endTime = getUserInput("End Time (0.6, 1.2, 1.8, 2.4, 3.0): ", 0.6, 3.0);
}
// Get user input with validation
float getUserInput(String prompt, float minVal, float maxVal) {
float value;
do {
Serial.print(prompt);
while (Serial.available() == 0) {
delay(100);
}
value = Serial.parseFloat();
} while (value < minVal || value > maxVal);
return value;
}
// Setup the Arduino
void setup() {
Serial.begin(9600);
lcd.begin(16, 2); // Initialize LCD with 16 columns and 2 rows
// Ask user for time frame
float startTime, endTime;
askUserInput(startTime, endTime);
// Determine the shading type and display the result
const char* shadingType = determineShadingType(startTime, endTime);
Serial.print("Shading Type: ");
Serial.println(shadingType);
// Display on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Shading: ");
lcd.setCursor(0, 1);
lcd.print(shadingType);
// Print the end time on a new line
Serial.print("End Time: ");
Serial.println(endTime);
// Check and print shaded panels (irradiance < 500) for the selected time frame
int timeIndex = getTimeIndex(startTime, endTime);
Serial.println("Shaded Panels:");
printShadedPanels(timeIndex);
}
void loop() {
// No need to run continuously
}
// Function to determine shading type based on time frame
const char* determineShadingType(float startTime, float endTime) {
if (startTime == 0.0 && endTime == 0.6) {
return shadingTypes[0]; // Bottom Shading
} else if (startTime == 0.6 && endTime == 1.2) {
return shadingTypes[1]; // L-Shaped Shading
} else if (startTime == 1.2 && endTime == 1.8) {
return shadingTypes[2]; // Corner Shading
} else if (startTime == 1.8 && endTime == 2.4) {
return shadingTypes[3]; // Center Shading
} else {
return shadingTypes[4]; // Side Shading
}
}
// Get the index of the time frame in the irradiance matrix
int getTimeIndex(float startTime, float endTime) {
for (int i = 0; i < 5; i++) {
if (timeFrames[i] == startTime && timeFrames[i + 1] == endTime) {
return i;
}
}
return -1; // Should not happen
}
// Print shaded panels based on irradiance values
void printShadedPanels(int timeIndex) {
for (int row = 0; row < 5; row++) {
for (int col = 0; col < 5; col++) {
if (irradiance[row][col][timeIndex] < 500) {
Serial.print("Panel (");
Serial.print(row + 1);
Serial.print(",");
Serial.print(col + 1);
Serial.println(") is shaded.");
}
}
}
}