## Shooting Star

This example shows how to make a ray of light, or more poetically a Shooting Star, go through a line of LEDs. You will be able to controle how fast the 'star' shoots, and how long its 'tail' is. It isn't very elegant because the tail is as bright as the star, and in the end it seems like a solid ray that crosses the LED line.

?v=0

### How this works

You connect 11 LEDs to 11 arduino digital pins, through a 220 Ohm resistance (see image above).

The program starts lighting up LEDs until it reaches the number of LEDs equal to the size you have stablished for the tail. Then it will continue lighting LEDs towards the left (if you mount it like and look at it like the image) to make the star keep movint, and will start erasing from the right, to make sure we see the tail (otherwise we would just light up the whole line of leds, this will happen also if the tail size is equal or bigger than 11)

The tail size should be relatively small in comparison with the number of LEDs in order to see it. Of course you can increase the number of LEDs using an LED driver (see tutorial) and therefore, allow longer tails.

### Code

``` /* ShootingStar
* ------------
* This program is kind of a variation of the KnightRider
* It plays in a loop a "Shooting Star" that is displayed
* on a line of 11 LEDs directly connected to Arduino
*
* You can control how fast the star shoots thanx to the
* variable called "waitNextLed"
*
* You can also control the length of the star's "tail"
* through the variable "tail length"
* First it reads two analog pins that are connected
* to a joystick made of two potentiometers
*
* @author: Cristina Hoffmann
* @hardware: Cristina Hofmann
*
*/
// Variable declaration
```

```  int pinArray [] = { 2,3,4,5,6,7,8,9,10,11,12 };    // Array where I declare the pins connected to the LEDs
int controlLed = 13;
int waitNextLed = 100;  // Time before I light up the next LED
int tailLength = 4;     // Number of LEDs that stay lit befor I start turning   them off, thus the tail
int lineSize = 11;       // Number of LEDs connected (which also is the size of the pinArray)
```

```  // I asign the sens of the different Pins
void setup()
{
int i;
pinMode (controlLed, OUTPUT);
for (i=0; i< lineSize; i++)
{
pinMode(pinArray[i], OUTPUT);
}
}
```

```  // Main loop
void loop()
{
int i;
int tailCounter = tailLength;   // I set up the tail length in a counter
digitalWrite(controlLed, HIGH); // I make sure I enter the loop indicating it with this LED
```

```     for (i=0; i<lineSize; i++)
{
digitalWrite(pinArray[i],HIGH); // I light up consecutively the LEDs
delay(waitNextLed);            // This time variable controles how fast I light them up
if (tailCounter == 0)
{
digitalWrite(pinArray[i-tailLength],LOW); // I turn off the LEDs depending on my tailLength
}
else
if (tailCounter > 0)
tailCounter--;
}
```

```    for (i=(lineSize-tailLength); i<lineSize; i++)
{
digitalWrite(pinArray[i],LOW); // I turn off the LEDs
delay(waitNextLed);            // This time variable controles how fast I light them upm, and turn off as well
}
```

}

@idea: Cristina Hoffmann

@code: Cristina Hoffmann

@pictures and graphics: Cristina Hoffmann

@date: 20060203 - Rennes - France