Ghost > 1st Prototype Movie
Ghost
   
1st Prototype Code
1 aruion board + 20 blue LEDs + 20 white LEDs + handmade switch

// declare variables:

int switchPin = 7;      //  digital input pin for a switch
int whitepinArray[] = {
  2,3,4,5,6 };    // Array where I declare the pins connected to the LEDs
int bluepinArray[] = {
  8,9,10,11,12 };    // Array where I declare the pins connected to the LEDs

int switchState = 0;    // the state of the switch

int waitNextLed = 100;  // Time before I light up the next LED
int tailLength = 3;     // Number of LEDs that stay lit befor I start turning   them off, thus the tail
int lineSize = 5;       // Number of LEDs connected (which also is the size of the pinArray)

void setup() {
  int i;
  int j;

  for (i=0; i< lineSize; i++)
  {
    pinMode(whitepinArray[i], OUTPUT);
  } 

  for (j=0; j< lineSize; j++)
  {
    pinMode(bluepinArray[j], OUTPUT);
  }

  pinMode(switchPin, INPUT);       // set the switch pin to be an input

}

void loop() {
  // read the switch input:
  switchState = digitalRead(switchPin);
  int i;
  int j;
  int tailCounter = tailLength;   // I set up the tail length in a counter


  if (switchState == 1) {
    // if the switch is closed:
    for (i=0; i < lineSize; i++)
    {
      digitalWrite(whitepinArray[i],HIGH); // I light up consecutively the LEDs
      delay(waitNextLed);            // This time variable controles how fast I light them up
      if (tailCounter == 0)
      {
        digitalWrite(whitepinArray[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(whitepinArray[i],LOW); // I turn off the LEDs
      delay(waitNextLed);            // This time variable controles how fast I light them upm, and turn off as well
    }

    for (j=0; j< 5; j++)
    {  
      digitalWrite(bluepinArray[j], LOW);       // turn off the red LED
    }

  } 
  else {
    // if the switch is open:
    for (i=0; i< 5; i++)
    {  
      digitalWrite(whitepinArray[i], LOW);       // turn off the red LED
    }

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

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

  }


}
Do you want to contact us?
Ji Sun Lee, Emery Martin, Robert C. Moon