const int ledPin = 9; // PWM-capable pin to which the LED is connected
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop() {
// Fade in the LED
for (int brightness = 0; brightness <= 255; brightness++) {
analogWrite(ledPin, brightness); // Set the brightness
delay(10); // Wait for 10 milliseconds to see the change
}
// Fade out the LED
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(ledPin, brightness); // Set the brightness
delay(10); // Wait for 10 milliseconds to see the change
}
}