CODE | LED Chase Lights - Arduino Project 005

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

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 | Based Security System with Lcd Display - Arduino Project 046

CODE | Based Security System with Lcd Display - Arduino Project 046

Components Needed: You will need an Arduino (like Arduino Uno or Nano), an LCD display, a keypa…

HELLO RUBY Child Coding

HELLO RUBY Child Coding

HELLO RUBY儿童编程大冒险儿童编程思维启蒙读本3-6岁:《Hello Ruby儿童编程大冒险》English Version 英文网站  http://www.hellor…

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 | Joystick Servo Control - Arduino Project 027

CODE | Joystick Servo Control - Arduino Project 027

In this tutorial, we are going to learn how to use Arduino and a joystick to control two servo motor…

C05 |   C/C++ Develop Environment

C05 | C/C++ Develop Environment

C语言教程05: C/C++开发环境C 语言编译器可以分为 C 和 C++两大类,其中 C++是 C 的超集,也支持 C 语言编程。事实上,编译器的选择不是最重要的,它们都可以完成基本的 C 语言编译…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.