/**
* Fades an LED on and off using analogWrite().
*
* On ESP32 Arduino core v3.x, analogWrite() is a convenience wrapper
* around the LEDC library. It defaults to 1 kHz PWM at 8-bit resolution.
* This is the simplest way to fade an LED—identical to Arduino Uno code!
*
* See: https://makeabilitylab.github.io/physcomp/esp32/led-fade
*/
const int LED_OUTPUT_PIN = 13; // GPIO 13
const int DELAY_MS = 8; // Small delay between steps for a smooth fade
void setup() {
// Set the LED output pin
pinMode(LED_OUTPUT_PIN, OUTPUT);
}
void loop() {
// Fade up: ramp from 0 (off) to 255 (full brightness)
for (int brightness = 0; brightness <= 255; brightness++) {
analogWrite(LED_OUTPUT_PIN, brightness);
delay(DELAY_MS);
}
// Fade down: ramp from 255 back to 0
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(LED_OUTPUT_PIN, brightness);
delay(DELAY_MS);
}
}