Luo Yi Tan – Arduino assignment: KITT lights

No fading

int ledPins[] = {2,3,4,5,6,7, 8, 9};

void setup()
{
  int index;
  for(index = 0; index <= 7; index++)
  {
    pinMode(ledPins[index],OUTPUT);
  }
}

void loop() {
  int index;
  int delayTime = 50; 

  for(index = 7; index >= 0; index--)
  {
    digitalWrite(ledPins[index], HIGH);
    delay(delayTime);
    digitalWrite(ledPins[index], LOW);
  }  
}

Fading

int ledPins[] = {3, 5, 6, 9, 10, 11};

void setup()
{
  int index;
  for(index = 0; index <= 7; index++)
  {
    pinMode(ledPins[index],OUTPUT);
  }
}

void loop() {
  int index;
  int delayTime = 1; 
  int delayTime2 = 100; 
  for(int fadeValue = 255 ; fadeValue > 0; fadeValue -=5) {  
      analogWrite(ledPins[index], fadeValue);            
      delay(5);                            
    }    
  }

  for(index = 5; index >= 0; index--)
    for(int fadeValue = 255 ; fadeValue > 0; fadeValue -=5) { 
      analogWrite(ledPins[index], fadeValue);            
      delay(5);                            
    }    

}

Wished I had a better camera, my ipod doesn’t have widescreen :(

Post a comment