// Define the PWM pin for controlling LED brightness
const int ledPin = 10; // Choose any PWM-capable pin (e.g., pin 9)
void setup() {
// Set the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Increase LED brightness gradually from off to full brightness
for (int brightness = 0; brightness <= 255; brightness++) {
analogWrite(ledPin, brightness);
delay(10); // Adjust delay time for smoother transition
}
// Decrease LED brightness gradually from full brightness to off
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(ledPin, brightness);
delay(10); // Adjust delay time for smoother transition
}
}