const byte NUMBER_OF_LEDS = 4;
const byte LED_PINS[] = {3, 4, 5 ,6};
const unsigned int DELAY_VALUE = 90;
void setup() {
// nothing happens in setup
}
void loop() {
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
lightUp(fadeValue);
}
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
lightUp(fadeValue);
}
}
void lightUp(const int fadeValue) {
const byte currLedPin = getCurrLedPin(fadeValue);
turnOffAllLeds();
analogWrite(currLedPin, fadeValue);
delay(DELAY_VALUE);
}
void turnOffAllLeds() {
for (byte i = 0; i < NUMBER_OF_LEDS; i++) {
analogWrite(LED_PINS[i], 0);
}
}
byte getCurrLedPin(const int fadeValue) {
if (fadeValue <= 64) {
return LED_PINS[0];
} else if (65 <= fadeValue && fadeValue <= 128) {
return LED_PINS[1];
} else if (129 <= fadeValue && fadeValue <= 192) {
return LED_PINS[2];
} else {
return LED_PINS[3];
}
}