// Complete Instructions: https://RandomNerdTutorials.com/esp32-digital-inputs-outputs-arduino/
// set pin numbers
float volt;
int x;
const int pot = 25;
const int r =19;
const int g = 18;
const int b= 5; // the number of the pushbutton pin
//const int ledPin = 21; // the number of the LED pin
// variable for storing the pushbutton status
int potState = 0;
void setup() {
Serial.begin(115200);
// initialize the pushbutton pin as an input
pinMode(pot, INPUT);
pinMode(r,OUTPUT);
pinMode(g,OUTPUT);
pinMode(b,OUTPUT);
// initialize the LED pin as an output
//pinMode(ledPin, OUTPUT);
}
void loop() {
// read the state of the pushbutton value
potState = analogRead(pot);
volt=potState*0.0008058608058;
if(volt <= 1.1){
digitalWrite(r, HIGH);
digitalWrite(g, LOW);
digitalWrite(b, LOW);
}
else if((volt > 1.1) && (volt < 2.2) ){
digitalWrite(r, LOW);
digitalWrite(g, HIGH);
digitalWrite(b, LOW);
}
else{
digitalWrite(r, LOW);
digitalWrite(g, LOW);
digitalWrite(b, HIGH);
}
Serial.print(volt);
Serial.print(" V ");
Serial.println(potState);
delay(1000);
//Serial.println(buttonState);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH
// if (potState == HIGH) {
// //turn LED on
// // digitalWrite(ledPin, HIGH);
// // Serial.println("button on");
// // Serial.println("ON");
// // delay(1000);
// Serial.println("Dark");
// } else {
// // turn LED off
// // digitalWrite(ledPin, LOW);
// // Serial.println("button Off");
// // Serial.println("LOw");
// // delay(1000);
// Serial.println("Bright");
// }
}