CODE | LED Chase Lights - Arduino Project 005

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

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

Series and parallel circuits

Series and parallel circuits

Two-terminal components and electrical networks can be connected in series or parallel. The resultin…

Install PrestaShop 1.7 Version

Install PrestaShop 1.7 Version

现在很多国内的公司为了拓展对外业务,开始采用更先进的电子商务软件,如美国的Amazon,加拿大的Shopify,法国的PrestaShop等都有很多用户在使用,对于商业初期的低成本尝试,开源软件Pre…

CODE | Control Stepper Motor ULN2004A - Arduino Project 029

CODE | Control Stepper Motor ULN2004A - Arduino Project 029

Stepper motors, due to their unique design, can be controlled to a high degree of accuracy without a…

CODE | Light Sensor - Arduino Project 014

CODE | Light Sensor - Arduino Project 014

This project introduces a new component known as a Light Dependent Resistor, or LDR. As the name imp…

CODE | Piezo Sounder Alarm - Arduino Project 011

CODE | Piezo Sounder Alarm - Arduino Project 011

Arduino project - sounder and sensors : Include project 11 Piezo Sounder Alarm ,Project piezo sounde…

CODE | Simple Motor Control - Arduino Project 015

CODE | Simple Motor Control - Arduino Project 015

First, you’re going to simply control the speed of a DC motor in one direction, using a power transi…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.