Files
esp32-learning/05-photoresistors/05-photoresistors.ino

20 lines
444 B
C++

#define PIN_PHOTORESISTOR 1
#define PIN_LED 14
#define ADC_MAX (1 << 12)
#define ADC_VOLTAGE 3300
void setup()
{
Serial.begin(115200);
ledcAttach(PIN_LED, 1000, 12);
}
void loop()
{
int adcvalue = analogRead(PIN_PHOTORESISTOR);
int adcvoltage = (ADC_MAX / ADC_VOLTAGE) * adcvalue;
Serial.printf("ADC Value: %d Voltage (int): %d\n", adcvalue, adcvoltage);
ledcWrite(PIN_LED, adcvoltage);
}