// https://deepbluembedded.com/esp32-digital-inputs-outputs-arduino/
#define LED_RED_GPIO 2
#define LED_GREEN_GPIO 32
#define BTN_GPIO 23
int BTN_State = 0; // Variable To Store Button State
int LED_GREEN_Brightness = 0; // how bright the LED is
int LED_GREEN_fadeAmount = 5; // how many points to fade the LED by
void setup()
{
pinMode(LED_RED_GPIO, OUTPUT);
pinMode(LED_GREEN_GPIO, OUTPUT);
pinMode(BTN_GPIO, INPUT);
}
void loop()
{
// Read The Button State
BTN_State = digitalRead(BTN_GPIO);
// Assign The BTN State To The LED Pin
digitalWrite(LED_RED_GPIO, BTN_State);
analogWrite(LED_GREEN_GPIO, LED_GREEN_Brightness);
// change the brightness for next time through the loop:
LED_GREEN_Brightness = LED_GREEN_Brightness + LED_GREEN_fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (LED_GREEN_Brightness <= 0 || LED_GREEN_Brightness >= 255) {
LED_GREEN_fadeAmount = -LED_GREEN_fadeAmount;
}
delay(20);
}