Knight Rider – Arduino

Sequência de 10 Led´s com o efeito luminoso do carro K.I.T.T.

Materiais

  • Arduino
  • Breadboard
  • 10x LED Vermelho
  • 10x Resistência 150R
  • 1x Resistência 10K
  • 1x Pushbutton
  • PCB Knight Rider (opcional)

Vídeo

Montagem

Knight Rider Arduino

Código (Arduino) – Download

const int buttonPin = 12;

int pinArray[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int count = 0;
int timer = 30;
int mode = 0;
int buttonState = 0;

void setup(){
    for (count=0;count<10;count++) {
        pinMode(pinArray[count], OUTPUT);
        pinMode(buttonPin, INPUT);
    }
}

void loop() {
    buttonState = digitalRead(buttonPin);
    
    if (buttonState == HIGH) {
        if (mode!=3){
            mode = mode+1;
        } else {
            mode=0;
        }
    }
    
    if (mode==0){
        for (count=0;count<9;count++) {
            digitalWrite(pinArray[count], HIGH);
            delay(timer);
            digitalWrite(pinArray[count + 1], HIGH);
            delay(timer);
            digitalWrite(pinArray[count], LOW);
            delay(timer*2);
        }
        for (count=9;count>0;count--) {
            digitalWrite(pinArray[count], HIGH);
            delay(timer);
            digitalWrite(pinArray[count - 1], HIGH);
            delay(timer);
            digitalWrite(pinArray[count], LOW);
            delay(timer*2);
        }
    } else if (mode==1) {
    
        for (count=0;count<9;count++) {
            digitalWrite(pinArray[count], HIGH);
            delay(timer);
        }
        for (count=0;count<9;count++) {
            digitalWrite(pinArray[count], LOW);
            delay(timer);
        }
        for (count=0;count<9;count++) {
            digitalWrite(pinArray[9-count], HIGH);
            delay(timer);
        }
        for (count=0;count<9;count++) {
            digitalWrite(pinArray[9-count], LOW);
            delay(timer);
        }
    
    } else if (mode==2) {
        for (count=0;count<5;count++) {
            digitalWrite(pinArray[4-count], HIGH);
            digitalWrite(pinArray[5+count], HIGH);
            delay(timer);
            digitalWrite(pinArray[6+count], HIGH);
            digitalWrite(pinArray[3-count], HIGH);
            
            digitalWrite(pinArray[4-count], LOW);
            digitalWrite(pinArray[5+count], LOW);
            delay(timer*2);
    }
    
    } else if (mode==3) {
        for (count=0;count<5;count++) {
            digitalWrite(pinArray[count], HIGH);
            digitalWrite(pinArray[9-count], HIGH);
            delay(timer);
            digitalWrite(pinArray[count + 1], HIGH);
            digitalWrite(pinArray[9-count - 1], HIGH);
            digitalWrite(pinArray[count], LOW);
            digitalWrite(pinArray[9-count], LOW);
            delay(timer*2);
        }
        for (count=0;count<4;count++) {
            digitalWrite(pinArray[4-count], HIGH);
            digitalWrite(pinArray[5+count], HIGH);
            delay(timer);
            digitalWrite(pinArray[6+count], HIGH);
            digitalWrite(pinArray[3-count], HIGH);
            digitalWrite(pinArray[4-count], LOW);
            digitalWrite(pinArray[5+count], LOW);
            delay(timer*2);
        }
    }
}

You may also like...

Deixe uma resposta

O seu endereço de email não será publicado. Campos obrigatórios marcados com *