#include <Servo.h>
Servo myservo;
const int LDR = 4; // Assuming LDR is connected to analog pin A0
int lint = 0; // Global variable to hold mapped light value
float cf = 0.75; // Calibration factor for the servo angle, adjust as needed
double angle = 0;
// Function to check light level using LDR module
void check_light() {
int light = analogRead(LDR);
Serial.println(light);
lint = map(light, 0, 4096, 0, 100); // For the dashboard, maps light level to 0 or 1
Serial.println(lint);
angle = lint/100;
//Serial.println(angle);
}
// Function for sliding the shaded window
void window() {
int deg = 180 * lint/100 * cf; // Servo turning angle
//Serial.print(deg);
myservo.write(deg);
delay(30);
}
void setup() {
myservo.attach(2); // Assuming the servo is connected to pin 9
Serial.begin(115200);
}
void loop() {
check_light(); // First, check the light level
window(); // Then, adjust the window based on the light level
delay(1000); // Wait for a second before the next check
}