Improve Knight Rider Circuit

by 苳梣 in Circuits > Arduino

361 Views, 0 Favorites, 0 Comments

Improve Knight Rider Circuit

20201123_011217.jpg
2020年11月23日

Change by: https://www.instructables.com/Knight-Rider-Circuit/

It's just a simple circuit that uses Arduino to make nine LEDs light up in different ways.

Supplies

  • 9 LED (same color)
  • Arduino Leonardo x 1
  • A 220 Ohm Resistor
  • 3 120 Ohm Resistor

Set Up the Circuit and the Button

original_f968266f-7c9d-429e-832f-d76444338095_20201123_002113.jpg
20201123_002124.jpg
作業用
擷取.PNG

Different from the circuit that I change, it will need 3 buttons to make it have more pattern.

Programing

20201123_010753.jpg
20201123_010855.jpg
int pin2 = 2;
int pin3 = 3;
int pin4 = 4;
int pin5 = 5;
int pin6 = 6;
int pin7 = 7;
int pin8 = 8;
int pin9 = 9;
int pin10 = 10;
int timer = 50;//改1:間隔時間從40改成50的;

void setup() {
  pinMode(pin2, OUTPUT);
  pinMode(pin3, OUTPUT);
  pinMode(pin4, OUTPUT);
  pinMode(pin5, OUTPUT);
  pinMode(pin6, OUTPUT);
  pinMode(pin7, OUTPUT);
  pinMode(pin8, OUTPUT);
  pinMode(pin9, OUTPUT);
  pinMode(pin10, OUTPUT);  
  pinMode(11, INPUT);
}

void loop() {

  digitalWrite(pin2, HIGH);
   delay(timer);
   digitalWrite(pin2, LOW);
   delay(timer);

   digitalWrite(pin3, HIGH);
   delay(timer);
   digitalWrite(pin3, LOW);
   delay(timer);

   digitalWrite(pin4, HIGH);
   delay(timer);
   digitalWrite(pin4, LOW);
   delay(timer);

   digitalWrite(pin5, HIGH);
   delay(timer);
   digitalWrite(pin5, LOW);
   delay(timer);

   digitalWrite(pin6, HIGH);
   delay(timer);
   digitalWrite(pin6, LOW);
   delay(timer);

  digitalWrite(pin7, HIGH);
   delay(timer);
   digitalWrite(pin7, LOW);
   delay(timer);
   
   digitalWrite(pin8, HIGH);
   delay(timer);
   digitalWrite(pin8, LOW);
   delay(timer);

   digitalWrite(pin9, HIGH);
   delay(timer);
   digitalWrite(pin9, LOW);
   delay(timer);
   
   digitalWrite(pin10, HIGH);
   delay(timer);
   digitalWrite(pin10, LOW);
   delay(timer);
    
   digitalWrite(pin10, HIGH);
   delay(timer);
   digitalWrite(pin10, LOW);
   delay(timer);
   
    digitalWrite(pin9, HIGH);
   delay(timer);
   digitalWrite(pin9, LOW);
   delay(timer);
   
   digitalWrite(pin8, HIGH);
   delay(timer);
   digitalWrite(pin8, LOW);
   delay(timer);
   
   digitalWrite(pin7, HIGH);
   delay(timer);
   digitalWrite(pin7, LOW);
   delay(timer);
  
   digitalWrite(pin6, HIGH);
   delay(timer);
   digitalWrite(pin6, LOW);
   delay(timer);

   digitalWrite(pin5, HIGH);
   delay(timer);
   digitalWrite(pin5, LOW);
   delay(timer);

   digitalWrite(pin4, HIGH);
   delay(timer);
   digitalWrite(pin4, LOW);
   delay(timer);

   digitalWrite(pin3, HIGH);
   delay(timer);
   digitalWrite(pin3, LOW);
   delay(timer);

  if (digitalRead ( 11 )) {
   digitalWrite(pin2, HIGH);  //改2:我增加了三個按鈕,每個if下面的動作都是自行增加的,
   digitalWrite(pin10, HIGH);
   delay(timer);
   
   digitalWrite(pin2, LOW);
   digitalWrite(pin10, LOW);
   delay(timer);

   digitalWrite(pin3, HIGH);
   digitalWrite(pin9, HIGH);
   delay(timer);
   
   digitalWrite(pin3, LOW);
   delay(timer);
   digitalWrite(pin9, LOW);
   delay(timer);

   digitalWrite(pin4, HIGH);
   digitalWrite(pin8, HIGH);
   delay(timer);
   
   digitalWrite(pin4, LOW);
   digitalWrite(pin8, LOW);
   delay(timer);

   digitalWrite(pin5, HIGH);
   digitalWrite(pin7, HIGH);
   delay(timer);
   
   digitalWrite(pin5, LOW);
   digitalWrite(pin7, LOW);
   delay(timer);

   digitalWrite(pin6, HIGH);
   delay(timer);
   digitalWrite(pin6, LOW);
   delay(timer);

  }

  if (digitalRead ( 12 )){

  for (int i = 0 ; i < 2  ; ++i ){
  digitalWrite (pin2, HIGH);
  digitalWrite (pin3, HIGH);
  digitalWrite (pin4, HIGH);
  digitalWrite (pin5, HIGH);
  digitalWrite (pin6, HIGH);
  delay(timer);

  digitalWrite (pin2, LOW);
  digitalWrite (pin3, LOW);
  digitalWrite (pin4, LOW);
  digitalWrite (pin5, LOW);
  digitalWrite (pin6, LOW);
  delay(timer);

  digitalWrite (pin6, HIGH);
  digitalWrite (pin7, HIGH);
  digitalWrite (pin8, HIGH);
  digitalWrite (pin9, HIGH);
  digitalWrite (pin10, HIGH);
  delay(timer);

  digitalWrite (pin6, LOW);
  digitalWrite (pin7, LOW);
  digitalWrite (pin8, LOW);
  digitalWrite (pin9, LOW);
  digitalWrite (pin10, LOW);
  delay(timer);

  }
  }

  if (digitalRead ( 13 )) {

    digitalWrite (pin6, HIGH); 
    delay(timer);
    digitalWrite (pin6, LOW);
    delay(timer);

    digitalWrite (pin5, HIGH);
    digitalWrite (pin7, HIGH);
    delay(timer);

    digitalWrite (pin5, LOW);
    digitalWrite (pin7, LOW);
    delay(timer);

    digitalWrite (pin4, HIGH);
    digitalWrite (pin8, HIGH);
    delay(timer);

    digitalWrite (pin4, LOW);
    digitalWrite (pin8, LOW);
    delay(timer);

    digitalWrite (pin3, HIGH);
    digitalWrite (pin9, HIGH);
    delay(timer);

    digitalWrite (pin3, LOW);
    digitalWrite (pin9, LOW);
    delay(timer);

    digitalWrite (pin2, HIGH);
    digitalWrite (pin10, HIGH);
    delay(timer);

    digitalWrite (pin2, LOW);
    digitalWrite (pin10, LOW);
    delay(timer);
    
  }
  


  }<br>

Download the code, and you can change the time of the interval or the order of the LEDs.