const int ledPin = A1; // Pin connected to the LED
int brightness = 0; // Variable to store the brightness level
int fadeAmount = 3; // Rate of change in brightness
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop() {
analogWrite(ledPin, brightness); // Set the LED brightness using PWM
brightness = brightness + fadeAmount; // Increment brightness
// Reverse the direction of fading when reaching brightness limits
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
delay(30); // Adjust the fading speed by changing the delay
}