const int ledPin = 13;
int brightness = 0; // Simulated brightness level (0–255)
int fadeAmount = 5; // How much to change brightness each cycle
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
// Simulate brightness by adjusting ON time
digitalWrite(ledPin, HIGH);
delay(brightness / 10); // ON duration scales with brightness
digitalWrite(ledPin, LOW);
delay((255 - brightness) / 10); // OFF duration scales inversely
// Update brightness
brightness += fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount; // Reverse direction
}
}