Arrays

This is the recreation of an example given to us in class.

// LED array

int ledPins []={13,12,11,10,9,8,7,6};
int numberLeds = 8;

void setup() {
 for (int i=0; i<numberLeds; i++){
  pinMode(ledPins[i], OUTPUT);
 }// for
 } //setup

void loop(){

for (int i=0; i<numberLeds; i++) { //switch them on sequentially
  digitalWrite(ledPins[i], HIGH);
  delay(100);
}
for (int i = numberLeds; i>0, i--;) { //switch them off sequentially
  digitalWrite(ledPins[i], LOW);
  delay(100);
}
}


Comments