On tutorial we will going to make a chasing LED, we will going to wire 10 LED to make an LED chase effect, similar to that used on the bikes and cars knight riders.
Electronic parts required
Arduino UNO/MEGA/MINI/NANO
10x LED
10x 220 Ohms Resistors
Jumper wires
Solder-less Breadboard
Wiring the LED to Arduino
Arduino Sketch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
/* 14core LED Chase Effect with 14Core Stater Kit */ byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Define the pins on arduino int ledDelay(65); // delay changes int leddirection = 1; int ledcurrentLED = 0; unsigned long changeTime; void setup() { for (int x=0; x<10; x++) { pinMode(ledPin[x], OUTPUT); } // set all pins to output changeTime = millis(); } void loop() { if ((millis() - changeTime) > ledDelay) { // if it has been ledDelay ms since last change changeLED(); changeTime = millis(); } } // Increment Function to turn off all LED void changeLED() { for (int x=0; x<10; x++) { // Increment x++ digitalWrite(ledPin[x], LOW); } digitalWrite(ledPin[ledcurrentLED], HIGH); // Turning on the current LED ledcurrentLED += leddirection; // increment the direction by value // changing the direction if we reach the last LED if (ledcurrentLED == 9) {leddirection = -1;} if (ledcurrentLED == 0) {leddirection = 1;} } |
LED Running Light or Chasing Light Effect
code does not work when I compile, something is missing.