//This shows how to use the switch case in arduino with LED
int led;
int delayTime =150;
void setup()
{
// initialize serial communication:
Serial.begin(9600);
// initializing the LED pins:
for (int LEDpin = 8; LEDpin <=13 ; LEDpin++) {
pinMode(LEDpin, OUTPUT);
// here, we have used for loop for initialization
}
}
void loop()
{
for(int i=1; i<=7; i++){
led=i; // this represent the differen cases
switch (led)
{
case 1:
digitalWrite(8, HIGH);
break;
case 2:
digitalWrite(9, HIGH);
break;
case 3:
digitalWrite(10, HIGH);
break;
case 4:
digitalWrite(11, HIGH);
break;
case 5:
digitalWrite(12, HIGH);
break;
case 6:
digitalWrite(13, HIGH);
break;
default:
// turn all the LEDs off if all the above cases does not matches:
for (int LEDpin = 8; LEDpin <=13; LEDpin++)
{
digitalWrite(LEDpin, LOW);
}
}
delay(delayTime);
}
}