//#####################configuração do fotoresistor
#define LDR_PIN 34 ///define o pino de leitura do fotoresistor
// LDR Characteristics
// Essas constantes devem corresponder aos atributos "gama" e "rl10" do fotoresistor
const float GAMMA = 0.7;
const float RL10 = 33;
int valorAnterior = 0; // Variável para armazenar o valor anterior
float lux=0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
Serial.println("Dilsonei - SKIC");
pinMode(LDR_PIN, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
int analogValue= analogRead(LDR_PIN);
if (analogValue != valorAnterior) {
float voltage = analogValue / 4096. * 3.3;
float resistance = 2000 * voltage / (1 - voltage / 3.3);
lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.print(lux);
Serial.println(" Lux");
// Atualiza o valor anterior com o novo valor
valorAnterior = analogValue;
}
}