#define ldrPin 34
const float gama = 0.7;
const float rl10 = 50;
const int ledPin = 16;
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
ledcSetup(ledChannel, freq, resolution);
// attach the channel to the GPIO to be controlled
ledcAttachPin(ledPin, ledChannel);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
int nilaiLDR = analogRead(ldrPin);
int dutycycle = map(nilaiLDR, 32, 4063, 255, 0);
Serial.println(dutycycle);
// nilaiLDR = map(nilaiLDR, 4095, 0, 1024, 0); //mengubah nilai pembacaan sensor LDR dari nilai ADC arduino menjadi nilai ADC ESP32
// float voltase = nilaiLDR / 1024.*5;
// float resistansi = 2000 * voltase / (1-voltase/5);
// float kecerahan = pow(rl10*1e3*pow(10,gama)/resistansi,(1/gama));
// Serial.print("Kecerahan = ");
// Serial.println(kecerahan);
//int PWMLED = map (kecerahan, 0, 85168.02, 255, 0 );
ledcWrite(ledChannel, dutycycle);
// // decrease the LED brightness
// for(int dutyCycle = 255; dutyCycle >= 0; dutyCycle--){
// // changing the LED brightness with PWM
// ledcWrite(ledChannel, dutyCycle);
// delay(15);
// }
}