/* MultipleLEDsTimer2 Cycle through three LEDs with a timer. This version uses a switch-case selection structure. */ const int delayTime = 500; // time to wait between LED changes const int led0 = 13; // connect an LED to pin 13 const int led1 = 12; // connect an LED to pin 12 const int led2 = 11; // connect an LED to pin 11 int ledState; // used to decide which LED is on (0 to 2) void setup() { // make LED pins outputs pinMode(led0, OUTPUT); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); // initialize state ledState = 0; // turn the correct LED on and the others off digitalWrite(led0, HIGH); digitalWrite(led1, LOW); digitalWrite(led2, LOW); } void loop() { delay(delayTime); ledState = (ledState + 1) % 3; // cycle through 0,1,2 // turn the correct LED on and the others off switch (ledState) { case 0: digitalWrite(led0, HIGH); digitalWrite(led1, LOW); digitalWrite(led2, LOW); break; case 1: digitalWrite(led0, LOW); digitalWrite(led1, HIGH); digitalWrite(led2, LOW); break; case 2: digitalWrite(led0, LOW); digitalWrite(led1, LOW); digitalWrite(led2, HIGH); break; default: digitalWrite(led0, HIGH); digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); break; } }