// Complete Instructions: https://RandomNerdTutorials.com/esp32-digital-inputs-outputs-arduino/
// set pin numbers
const int sensorPin = 27; // the number of the pushbutton pin
const int ledPin = 21;
const int r=21;
const int g=5; // the number of the LED pin
// variable for storing the pushbutton status
int sensorState = 0;
void setup() {
Serial.begin(115200);
// initialize the pushbutton pin as an input
pinMode(sensorPin, INPUT);
// initialize the LED pin as an output
pinMode(r, OUTPUT);
pinMode(g, OUTPUT);
}
void loop() {
// read the state of the pushbutton value
sensorState = digitalRead(sensorPin);
delay(1000);
//Serial.println(buttonState);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH
if (sensorState == HIGH) {
//turn LED on
digitalWrite(r, HIGH);
digitalWrite(g, LOW);
Serial.println("ON");
Serial.println("Dark");
} else {
// turn LED off
digitalWrite(g, HIGH);
digitalWrite(r, LOW);
Serial.println("OFF");
Serial.println("Bright");
}
}