#include <Arduino.h>
const int LED1 = 21; // set pin for the first LED
const int LED2 = 22; // set pin for the second LED
const int LDR = 32; // set pin for photoresistor (use pin number 35 for GPIO35 on ESP32)
int inputval = 0; // variable for values to be read from LDR
int outval = 0; // variable for output value from LDR
void setup() {
// Initialize pinModes
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LDR, INPUT);
}
void loop() {
// Read LDR value
inputval = analogRead(LDR);
// Map the 12-bit analog input to the 8-bit PWM range
outval = map(inputval, 0, 4095, 0, 255);
// Constrain output values within 0-255 range
int lightval = constrain(outval, 0, 255);
// Write the value to the first LED
analogWrite(LED1, lightval);
// Write the value to the second LED
analogWrite(LED2, lightval);
delay(10);
}