Link Ads

More search type here...

Showing posts with label Running LED Knight Rider using Arduino. Show all posts
Showing posts with label Running LED Knight Rider using Arduino. Show all posts

January 5, 2024

Running LED Knight Rider using Arduino

 Schematic


 The code:

int ledPins[] = {13, 12, 11, 10, 9, 8, 7, 6,5,4};
int numLEDs = sizeof(ledPins) / sizeof(ledPins[0]);
int delayTime = 80; // Waktu tunda dalam milidetik

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

void loop() {
  for (int i = 0; i < numLEDs; i++) {
    digitalWrite(ledPins[i], HIGH);
    delay(delayTime);
    digitalWrite(ledPins[i], LOW);
  }
  for (int i = numLEDs - 1; i >= 0; i--) {
    digitalWrite(ledPins[i], HIGH);
    delay(delayTime);
    digitalWrite(ledPins[i], LOW);
  }
}