Labels

Monday, April 17, 2017

LEDs blink in a sequence with Arduino [Knight Rider]

LEDs blink in a sequence with Arduino [Knight Rider]


We all remember TV-series from the 80's Knight Rider. So  there was a car with LED flash. This time I used Arduino UNO board to program LED display, here I used 10 LED bulbs. There are many way to program micro chip in Arduino.


Knight Rider 1

void setup() {

  
     pinMode(2,OUTPUT);
       pinMode(3,OUTPUT);
         pinMode(4,OUTPUT);
           pinMode(5,OUTPUT);
             pinMode(6,OUTPUT);
               pinMode(7,OUTPUT);
                pinMode(8,OUTPUT);
                 pinMode(9,OUTPUT);
                  pinMode(10,OUTPUT);
                   pinMode(11,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
    for(int i=1;i<12;i=i+1)
 {
  digitalWrite(i,HIGH);
  digitalWrite(i+1,HIGH);
  digitalWrite(i+2,HIGH);
  
  delay(100);
  digitalWrite(i,LOW);
  digitalWrite(i+1,LOW);
  digitalWrite(i+2,LOW);
  
 }

for(int i =12 ;i>=1;i--)
 {
  digitalWrite(i,HIGH);
   digitalWrite(i-1,HIGH);
    digitalWrite(i-2,HIGH);
  delay(100);
  digitalWrite(i,LOW);
   digitalWrite(i-1,LOW);
     digitalWrite(i-2,LOW);
  
 }
}

Knight Rider 2

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

int delayTime = 100;
void setup() {
  // put your setup code here, to run once:
for (int i=0;i<11;i++) {
    pinMode(pinArray[i], OUTPUT);
  }
}

void loop() {
  for (int i=2;i<11;i++) {
   digitalWrite(pinArray[i], HIGH);   
   digitalWrite(pinArray[i+1], HIGH);
   digitalWrite(pinArray[i+2], HIGH);
     delay(delayTime);

    digitalWrite(pinArray[i], LOW);   
   digitalWrite(pinArray[i+1], LOW);
   digitalWrite(pinArray[i+2], LOW);
  }
  for (int i=11;i>=2;i--) { 

  digitalWrite(pinArray[i],HIGH);
  digitalWrite(pinArray[i-1],HIGH);
  digitalWrite(pinArray[i-2],HIGH);
    delay(delayTime);
  digitalWrite(pinArray[i],LOW);
  digitalWrite(pinArray[i-1],LOW);
  digitalWrite(pinArray[i-2],LOW);
  }

}







No comments:

Post a Comment