Michael Importico – Arduino Knight Rider

Arduino Knight Rider LED from Michael Importico on Vimeo.

 
int sensorPin = 0;  //middle sensor wire on pot @ analog 0

int ledPin1 = 13; //LED connected digital pin
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int ledPin5 = 9;
int ledPin6 = 8;

void setup(){
  pinMode(ledPin1, OUTPUT); //ledPin is a digital output at this pin
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
}
void loop(){
  int sensorValue; //an interger named sensorValue
  sensorValue = analogRead(sensorPin);//sets sensorValue to pot reading

  digitalWrite(ledPin1, HIGH);//turn on ledPin1
  delay(sensorValue);//wait time as set by pot
  digitalWrite(ledPin1, LOW);//turn off ledPin1
  delay(sensorValue);//wait time as set by pot

  digitalWrite(ledPin2, HIGH);
  delay(sensorValue);
  digitalWrite(ledPin2, LOW);
  delay(sensorValue);

  digitalWrite(ledPin3, HIGH);
  delay(sensorValue);
  digitalWrite(ledPin3, LOW);
  delay(sensorValue);

  digitalWrite(ledPin4, HIGH);
  delay(sensorValue);
  digitalWrite(ledPin4, LOW);
  delay(sensorValue);

  digitalWrite(ledPin5, HIGH);
  delay(sensorValue);
  digitalWrite(ledPin5, LOW);
  delay(sensorValue);

  digitalWrite(ledPin6, HIGH);
  delay(sensorValue);
  digitalWrite(ledPin6, LOW);
  delay(sensorValue);

  digitalWrite(ledPin5, HIGH);
  delay(sensorValue);
  digitalWrite(ledPin5, LOW);
  delay(sensorValue);

  digitalWrite(ledPin4, HIGH);
  delay(sensorValue);
  digitalWrite(ledPin4, LOW);
  delay(sensorValue);

  digitalWrite(ledPin3, HIGH);
  delay(sensorValue);
  digitalWrite(ledPin3, LOW);
  delay(sensorValue);

  digitalWrite(ledPin2, HIGH);
  delay(sensorValue);
  digitalWrite(ledPin2, LOW);
  delay(sensorValue);
}

Post a comment