Wednesday 2 December 2015

Arduino Lab 2 Multi LED: Mandatory Challenge Completed

The following code is what I wrote to complete Arduino Lab 2 mandatory challenge. Visual evidence are also provided.

Code:

int ledPins[] = {1,2,3,4,5,6};
void setup()
{
  for(int x=0; x<7;x++)
  {
  pinMode(ledPins[x],OUTPUT);
  }
}
void loop()
{
  int delaytime = 800;
  for(int x=0; x<=6; x+=2)
  {
    digitalWrite (ledPins [x], HIGH);
    delay(delaytime);
  }
  for(int x=1; x<=5; x+=2)
  {
    digitalWrite (ledPins [x], HIGH);
    delay(delaytime);
  }
  for(int x=6; x>=0; x-=2)
  {
    digitalWrite (ledPins [x], LOW);
    delay(delaytime);
  }
  for(int x=5; x>=1; x-=2)
  {
    digitalWrite (ledPins [x], LOW);
    delay(delaytime);
  }
}

Visual Evidence:





No comments:

Post a Comment