#define LEDR 23 // yellow LED
#define LEDG 18 // green LED
#define ADC_IN A5
#define ADC_REF 3.3
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(LEDR,OUTPUT);
pinMode(LEDG,OUTPUT);
}
void loop() {
int adcRes=analogRead(ADC_IN);
// put your main code here, to run repeatedly:
delay(500); // this speeds up the simulation
float voltage = (float) adcRes*ADC_REF/4095;
Serial.println(adcRes); // display the reading in 1 decimal place
// adcRes is the ... value while voltage is the raw value
if(adcRes<=1000) // less than 1000, green will turn ON
{
digitalWrite(LEDR,HIGH); // have to switch off the other LED or else it remains on if we don't instruct it
digitalWrite(LEDG,LOW);
}
if (adcRes>1000 && adcRes<3500) // between 1000 and 3500, red will turn ON
{
digitalWrite(LEDR,LOW);
digitalWrite(LEDG,HIGH);
}
else if(adcRes>=3500) // above 3500, both LEDs will turn on
{
digitalWrite(LEDG,LOW);
digitalWrite(LEDR,LOW);
}
}