Ex03 – Controlling Multiple LEDs

oweek_e03 oweek_e03b

► Task
Control two LEDs by two digital pins.

The code below control two LED on and off at the same time.

void setup()   {
   pinMode(1, OUTPUT); // initialize the digital pin as an output:
   pinMode(8, OUTPUT); // initialize the digital pin as an output:
}

void loop() {
   digitalWrite(1, HIGH);   // set the LED on  
   digitalWrite(8, HIGH);   // set the LED on
   delay(1000);                  // wait for a second
   digitalWrite(1, LOW);    // set the LED off
   digitalWrite(8, LOW);    // set the LED off
   delay(1000);                  // wait for a second (1000 milli seconds)
}

The code below control one LED on and another off, and vice versa.

void setup()   {
   pinMode(1, OUTPUT); // initialize the digital pin as an output:
   pinMode(8, OUTPUT); // initialize the digital pin as an output:
}

void loop() {
   digitalWrite(1, HIGH);   // set the LED on  
   digitalWrite(8, LOW);   // set the LED off
   delay(1000);                  // wait for a second
   digitalWrite(1, LOW);    // set the LED off
   digitalWrite(8, HIGH);    // set the LED on
   delay(1000);                  // wait for a second (1000 milli seconds)
}