Robojax

Lesson 57: Using Array and Loop with Arduino

Lesson 57: Using Array and Loop with Arduino

Please select other codes for this lecture from the links below.

Part 6: Arduino Practiall Programming

In this lesson we learn how what an array is and how to define it. Please watch full details video. list of tipcs listed below.
Comparing two codes.


  int led[] ={2, 3, 4, 5};// define LED pins in array


void setup() {
  for(int i=0; i<4; i++)
  {
    pinMode(led[i], OUTPUT);// Define a pin as output   
  }
 

  
  Serial.begin(9600);// initialize serial monitor

}

void loop() {
  for(int i=0; i<4; i++)
  {
      digitalWrite(led[i],LOW); // turn all LEDs OFF
  }

  delay(1000);// wait for 1 secdond

  for(int i=0; i<4; i++)
  {
    digitalWrite(led[i],HIGH); // turn LED ON
    delay(1000);// wait for 1 secdond
  }    
 
      

}