CODE | LED Chase Lights - Arduino Project 005

RonWang3 years ago (2023-06-07)电子编程 COD9

You’re going to use a string of LEDs (10 in total) to make an LED chase effect, similar to that used on the car KITT on Knight Rider or on the face of the Cylons in Battlestar Galactica. This project will introduce the concept of arrays.

项目5 Project 5-LED Chase Effect

05 LED Chase Effect Circuit

/* Coding Ron Wang
   June 18th 2024
   Autaba support for coding hardware
 */
// Project 5 - LED Chase Effect

byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Create array for LED pins
int ledDelay(65); // delay between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
void setup() {
 for (int x=0; x<10; x++) { // set all pins to output
 pinMode(ledPin[x], OUTPUT); }
 changeTime = millis();
}
void loop() {
 if ((millis() - changeTime) > ledDelay) { // if it has been ledDelay ms since last change
 changeLED();
 changeTime = millis();
 }
}
void changeLED() {
 for (int x=0; x<10; x++) { // turn off all LED's
 digitalWrite(ledPin[x], LOW);
 }
 digitalWrite(ledPin[currentLED], HIGH); // turn on the current LED
 currentLED += direction; // increment by the direction value
 // change direction if we reach the end
 if (currentLED == 9) {direction = -1;}
 if (currentLED == 0) {direction = 1;}
}

             

Share with Friends:

Related Articles

DIY - Monochrome Light Cube Maker Introduction Step by Step

DIY - Monochrome Light Cube Maker Introduction Step by Step

First, let's take a look at the complete welded diagram (the shell needs to be purchased separat…

Books Exploring Arduino Book by Jeremy Blum

Books Exploring Arduino Book by Jeremy Blum

Exploring Arduino uses the popular Arduino microcontroller platform as an instrument…

CODE | SD Card Temperature Datalogger - Arduino Project 043

CODE | SD Card Temperature Datalogger - Arduino Project 043

Todady I made a simple Arduino datalogger using SD card and DHT11  relative humidity and t…

CODE | Piezo Sounder Melody Player - Arduino Project 012

CODE | Piezo Sounder Melody Player - Arduino Project 012

Rather than using the piezo to make annoying alarm sounds, why not use it to play a melody? You are…

CODE | LED Interactive Chase Effect - Arduino Project 006

CODE | LED Interactive Chase Effect - Arduino Project 006

Leave your circuit board intact from Project 5. You’re just going to add a potentiometer to this cir…

Electric and Sensor Control System

Electric and Sensor Control System

Since 2022, the founder of Autaba EC deparrment has devoted to the research and development of advan…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.