CODE | LED Chase Lights - Arduino Project 005

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

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 T12 Soldering (Full-Assembled Kits)

DIY T12 Soldering (Full-Assembled Kits)

前两天我们刚做了一起T12焊台的半散件的DIY组装,但是很多小伙伴反应这个版本的不够过瘾,对T12焊台的结构还是一知半解的,所以今天我们在上一期的基础上做一期特别的,全散件T12零件包的DIY组装视频…

CODE | Input and Output- Arduino Programming Basic

CODE | Input and Output- Arduino Programming Basic

The pins on the Arduino can be configured as either inputs or outputs. This document explains the fu…

CODE | SD Card Information Basic - Arduino Project 042

CODE | SD Card Information Basic - Arduino Project 042

Arduino Programming Basic -- Reading and Writing to an SD CardSD cards have non-volatile flash memor…

CODE | L293D Motor Driver IC - Arduino Project 016

CODE | L293D Motor Driver IC - Arduino Project 016

In the previous project, you used a transistor to control the motor. In this project, you are going…

CODE | Bollean - Arduino Programming Basic

CODE | Bollean - Arduino Programming Basic

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静…

CODE | Liquid Crystal Displays-Serial to Display - Arduino Project 023C

CODE | Liquid Crystal Displays-Serial to Display - Arduino Project 023C

Before wiring the LCD screen to your Arduino board we suggest to solder a pin header strip to the 14…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.