// #include <PubSubClient.h>
// #include <NTPClient.h>
// // #include "DHTesp.h"
// #include <WiFi.h>
#define LDR_1 12 // Replace with your chosen analog pin
#define LDR_2 14
#define LED 13 // Replace with your chosen digital pin
int LDR_1_Value; // Variable to store the analog reading from the LDR
int LDR_2_Value;
double brightness_1; // Variable to store the calculated brightness value
int brightness_2;
//const int DHT_PIN = 27;
// DHTesp dhtSensor;
// mqttClient the variable
//PubSubClient mqttClient(espClient);
char LDR_1_Ar[6];
// #include <ESP32Servo.h> // Include the Servo library (might need installation)
// const int servoPin = D2; // Replace with your chosen digital pin
// Servo myservo; // Create a Servo object
// int pos = 0; // Variable to store the servo position
void setup() {
Serial.begin(115200); // Start serial communication for monitoring
pinMode(LDR_1, INPUT); // Set the LDR pin as an input
// pinMode(LDR_2, INPUT);
// pinMode(LED, OUTPUT); // Set the LED pin as an output
// dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
//myservo.attach(servoPin); // Attach the servo to the specified pin
}
void loop() {
LDR_1_Value = analogRead(LDR_1); // Read the analog value from the LDR
Serial.println(LDR_1_Value); // Print the sensor value to the serial monitor
delay(1000); // Delay for 1 second
// LDR_2_Value = analogRead(LDR_2); // Read the analog value from the LDR
// Serial.println(LDR_2_Value); // Print the sensor value to the serial monitor
// delay(1000);
// Map the LDR reading (0-1023) to a brightness value (0-255) for PWM
brightness_1 = map(LDR_1_Value, 32, 4063, 0, 1);
Serial.println(brightness_1);
// Use PWM (Pulse Width Modulation) to control LED brightness
//analogWrite(LED, brightness_1);
// brightness_2 = map(LDR_2_Value, 32, 4063, 0, 255);
// Serial.println(brightness_2);
// // Use PWM (Pulse Width Modulation) to control LED brightness
//analogWrite(LED, brightness_2);
// if (brightness_1 > brightness_2){
// digitalWrite(LED, HIGH);
// }else{
// digitalWrite(LED, LOW);
// }
dtostrf(brightness_1, 0, 0, LDR_1_Ar);
// itoa(brightness_1, LDR_1_Ar, 10);
Serial.println(LDR_1_Ar);
delay(500);
// digitalWrite(LED, HIGH);
// delay(1000);
// digitalWrite(LED, LOW);
// delay(1000);
// for (pos = 0; pos <= 180; pos += 1) { // Sweep from 0 to 180 degrees
// myservo.write(pos); // Tell the servo to go to this position
// delay(15); // Wait for 15 milliseconds
// }
// for (pos = 180; pos >= 0; pos -= 1) { // Sweep back from 180 to 0 degrees
// myservo.write(pos);
// delay(15);
// }
}
// int ledPin = 9; // LED connected to digital pin 9
// int analogPin = 3; // potentiometer connected to analog pin 3
// int val = 0; // variable to store the read value
// void setup() {
// pinMode(ledPin, OUTPUT); // sets the pin as output
// }
// void loop() {
// val = analogRead(analogPin); // read the input pin
// analogWrite(ledPin, val / 4);
// // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
// }