#define LED_PIN_1 2
#define LED_PIN_2 3
#define LED_PIN_3 4
#define LED_NUMBER 3
byte LEDPinArray[LED_NUMBER] = { LED_PIN_1,
LED_PIN_2,
LED_PIN_3 };
int LEDIndex = 0;
void initAllLEDs()
{
for (int i = 0; i < LED_NUMBER; i++) {
pinMode(LEDPinArray[i], OUTPUT);
}
}
void powerOnSelectedLEDOnly(int index)
{
for (int i = 0; i < LED_NUMBER; i++) {
if (i == index) {
digitalWrite(LEDPinArray[i], HIGH);
}
else {
digitalWrite(LEDPinArray[i], LOW);
}
}
}
void toggleNextLED()
{
LEDIndex++;
if (LEDIndex >= LED_NUMBER) {
LEDIndex = 0;
}
powerOnSelectedLEDOnly(LEDIndex);
}
void setup()
{
initAllLEDs();
digitalWrite(LEDPinArray[LEDIndex], HIGH);
}
void loop()
{
delay(1000);
toggleNextLED();
}