Ghost > Final ProductionCode
Ghost
   
Final Production Code
1 aruion board + 180 LEDs + 2 handmade conductive fabric switches
int leftSwitchPin=2;
int rightSwitchPin=13;
int leftLEDpin1 = 3;
int leftLEDpin2 = 4;
int ghostLEDpin1 = 5;
int ghostLEDpin2 = 6;
int ghostLEDpin3 = 7; 
int ghostLEDpin4 = 8; 
int ghostLEDpin5 = 9;
int ghostLEDpin6 = 10; 
int rightLEDpin1 = 11;
int rightLEDpin2 = 12; 

int leftGhostLEDArray[] = {
  leftLEDpin1, leftLEDpin2, ghostLEDpin1, ghostLEDpin2, ghostLEDpin3, ghostLEDpin4,ghostLEDpin5,ghostLEDpin6};
int rightGhostLEDArray[] = {
  rightLEDpin2, rightLEDpin1, ghostLEDpin6, ghostLEDpin5, ghostLEDpin4, ghostLEDpin3, ghostLEDpin2, ghostLEDpin1};


int leftVal = 0; // left variable for reading the pin status
int leftCounter = 0;
int leftCurrentState = 0;
int leftPreviousState = 0;

int rightVal = 0; // right variable for reading the pin status
int rightCounter = 0;
int rightCurrentState = 0;
int rightPreviousState = 0;

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 = 8;       // Number of LEDs connected (which also is the size of the pinArray)

int left_run_count = 0;
int right_run_count = 0;

void setup() {
  pinMode(leftSwitchPin,INPUT);
  pinMode(rightSwitchPin,INPUT); 
  pinMode(leftLEDpin1, OUTPUT); 
  pinMode(leftLEDpin2, OUTPUT); 
  pinMode(ghostLEDpin1, OUTPUT);
  pinMode(ghostLEDpin2, OUTPUT);
  pinMode(ghostLEDpin3, OUTPUT);
  pinMode(ghostLEDpin4, OUTPUT);
  pinMode(ghostLEDpin5, OUTPUT);
  pinMode(ghostLEDpin6, OUTPUT);
  pinMode(rightLEDpin1, OUTPUT); 
  pinMode(rightLEDpin2, OUTPUT);
  beginSerial(9600);
}

void loop(){
  int i;  // array int for Ghost LED
  int tailCounter = tailLength;   // I set up the tail length in a counter

  //left side start
  leftVal = digitalRead(leftSwitchPin); // read input value
  if (leftVal == HIGH) { // check if the input is HIGH (button released)
    leftCurrentState = 1;
  } 
  else {
    leftCurrentState = 0;
  }
  if(leftCurrentState != leftPreviousState){
    if(leftCurrentState == 1){
      leftCounter = leftCounter + 1;
      Serial.print("leftCounter = ");
      Serial.println(leftCounter);
    }
  }
  leftPreviousState = leftCurrentState;

  switch(leftCounter){
  case 0:
    delay(30);
    // turn LED off
    digitalWrite(leftLEDpin1,LOW);
    digitalWrite(leftLEDpin2,LOW);
    digitalWrite(ghostLEDpin1,LOW);
    digitalWrite(ghostLEDpin2,LOW);
    digitalWrite(ghostLEDpin3,LOW);
    digitalWrite(ghostLEDpin4,LOW);
    digitalWrite(ghostLEDpin5,LOW);
    digitalWrite(ghostLEDpin6,LOW);
    digitalWrite(rightLEDpin1,LOW);
    digitalWrite(rightLEDpin2,LOW);
    left_run_count = 0; 
    break;
  case 1:
    // turn left & ghost LED on
    if ( left_run_count >= 2 ) {
   
      // turn everything on 
      int jj; 
      for ( jj = 2; jj < lineSize; jj++ ) {
         digitalWrite(leftGhostLEDArray[jj],HIGH);
      }
    } else { 
     // runs sequence 
    left_run_count++;
    for (i=0; i < lineSize; i++ ) 
    {
      digitalWrite(leftGhostLEDArray[i],HIGH); // I light up consecutively the LEDs
      delay(waitNextLed);            // This time variable controles how fast I light them up
      if (tailCounter == 0)
      {
        digitalWrite(leftGhostLEDArray[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(leftGhostLEDArray[i],LOW); // I turn off the LEDs
      delay(waitNextLed);            // This time variable controles how fast I light them upm, and turn off as well
    }
    }

    break;
  case 2:
    leftCounter = 0;
    left_run_count = 0;
  }

  // right side start

  rightVal = digitalRead(rightSwitchPin); // read input value
  if (rightVal == HIGH) { // check if the input is HIGH (button released)
    rightCurrentState = 1;
  } 
  else {
    rightCurrentState = 0;
  }
  if(rightCurrentState != rightPreviousState){
    if(rightCurrentState == 1){
      rightCounter = rightCounter + 1;
      Serial.print("rightCounter = ");
      Serial.println(rightCounter);
    }
  }
  rightPreviousState = rightCurrentState;



  switch(rightCounter){
  case 0:
    delay(30);
    // turn LED off
    digitalWrite(leftLEDpin1,LOW);
    digitalWrite(leftLEDpin2,LOW);
    digitalWrite(ghostLEDpin1,LOW);
    digitalWrite(ghostLEDpin2,LOW);
    digitalWrite(ghostLEDpin3,LOW);
    digitalWrite(ghostLEDpin4,LOW);
    digitalWrite(ghostLEDpin5,LOW);
    digitalWrite(ghostLEDpin6,LOW);
    digitalWrite(rightLEDpin1,LOW);
    digitalWrite(rightLEDpin2,LOW);
    right_run_count = 0; 
    break;
  case 1:
    // turn LED on
     if ( right_run_count >= 2 ) {
   
      // turn everything on 
      int jj; 
      for ( jj = 2; jj < lineSize; jj++ ) {
         digitalWrite(leftGhostLEDArray[jj],HIGH); 
      }
    } else { 
     // runs sequence 
    right_run_count++;    
    for (i=0; i < lineSize; i++)
    {
      digitalWrite(rightGhostLEDArray[i],HIGH); // I light up consecutively the LEDs
      delay(waitNextLed);            // This time variable controles how fast I light them up
      if (tailCounter == 0)
      {
        digitalWrite(rightGhostLEDArray[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(rightGhostLEDArray[i],LOW); // I turn off the LEDs
      delay(waitNextLed);            // This time variable controles how fast I light them upm, and turn off as well
    }
    }

    break;
  case 2:
    rightCounter = 0;
    right_run_count = 0; 
  }
}

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