Monday, 31 October 2011

CIRC-02: Multiple LEDs

Purpose: 
Get 8 LEDs to blink on and off in a sequence.

Equipment:
-8 x LED
-10 x Wires
-8 x 560ohm resistor
-1 x Arduino Uno
-1 x Breadboard

Reference:
http://www.oomlout.com/a/products/ardx/circ-02

Program Details: 
This experiment had included arrays. functions, and for loops in the code. It was fairly simple to pick up since the Arduino language is similar to Java.

Time to Complete: 
20 minutes

Results:
No errors with this experiment, LEDs lit up without a problem.

Photos of Project: 




Tips:
Similar to CIRC-01, just with 8 LEDs this time. Keep your LEDs, resistors, and wires consistently spaced out.

Further Work:
Change the sequence by playing with the order of the on and off lines of code.

Program Modifications:
The program is exactly the one from http://www.oomlout.com/a/products/ardx/circ-02

Program:

//An array that hold the pin each LED is connected to
int ledPins[] = {2,3,4,5,6,7,8,9};

void setup()
{
  for(int i = 0; i < 8; i++)      //loop to initialize each pin as an output
  {  
      pinMode(ledPins[i],OUTPUT); 
  }                                   
 
}
 
 

void loop()                     // Continuously runs
{
  oneAfterAnotherNoLoop();   //calls the function oneAfterAnotherNoLoop 
}
 

void oneAfterAnotherNoLoop()
 {
  int delayTime = 100; //sets a delay time
//turns LEDs on
  digitalWrite(ledPins[0], HIGH);  /*changes state of LED connected to pin 2  to high(on)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[1], HIGH);  /*changes state of LED connected to pin 3  to high(on)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[2], HIGH);  /*changes state of LED connected to pin 4  to high(on)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[3], HIGH);  /*changes state of LED connected to pin 5  to high(on)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[4], HIGH);  /*changes state of LED connected to pin 6  to high(on)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[5], HIGH);  /*changes state of LED connected to pin 7  to high(on)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[6], HIGH);  /*changes state of LED connected to pin 8  to high(on)*/
  delay(delayTime);                ////delay equal to the value of delayTime
  digitalWrite(ledPins[7], HIGH);  /*changes state of LED connected to pin 9  to high(on)*/

  delay(delayTime);                //delay equal to the value of delayTime
 //Turns LEDs off
  digitalWrite(ledPins[7], LOW);  //*changes state of LED connected to pin 2  to high(on)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[6], LOW);  //*changes state of LED connected to pin 3  to high(off)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[5], LOW);  //*changes state of LED connected to pin 4  to high(off)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[4], LOW);  //*changes state of LED connected to pin 5  to high(off)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[3], LOW);  //*changes state of LED connected to pin 6  to high(off)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[2], LOW);  //*changes state of LED connected to pin 7  to high(off)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[1], LOW);  //*changes state of LED connected to pin 8  to high(off)*/
  delay(delayTime);                //delay equal to the value of delayTime
  digitalWrite(ledPins[0], LOW);  //*changes state of LED connected to pin 9  to high(off)*/
  delay(delayTime);                //delay equal to the value of delayTime
 } 

}

No comments:

Post a Comment