// Potentiometer is connected to GPIO 34 (Analog ADC1_CH6)
const int potPin = 15;
// variable for storing the potentiometer value
int ADC = 0;
float volt = 0.0;
void setup() {
Serial.begin(115200);
pinMode(4, OUTPUT);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT);
delay(1000);
}
void loop() {
// Reading potentiometer value
ADC = analogRead(potPin);
volt = 3.3*ADC/4095;
Serial.print("Analog value: ");
Serial.print(ADC);
Serial.print(" volt: ");
Serial.println(volt);
delay(100);
if (volt >= 0.4 && volt < 0.8) {
digitalWrite(4, HIGH);
delay(200);
}
if (volt >= 0.8 && volt < 1.65 ) {
digitalWrite(2, HIGH);
delay(200);
}
if (volt >= 1.65 && volt <= volt) {
digitalWrite(13, HIGH);
delay(200);
}
else{
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(13, LOW);
}
}