const int redLed = 2;
const int yellowLed = 3;
const int duration = 100;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
}
void loop() {
fade(redLed, 10, 10);
delay(500);
fade(yellowLed, 10, 10);
delay(500);
}
void fade(int ledPin, int inc, int dec) {
for (int bright = 0; bright <= 255; bright += inc) {
analogWrite(ledPin, bright);
delay(duration);
}
for (int bright = 255; bright >= 0; bright -= dec) {
analogWrite(ledPin, bright);
delay(duration);
}
analogWrite(ledPin, 0);
}