CODE | LED Chase Lights - Arduino Project 005

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

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

Setting Up an LNMP Environment on CentOS 7.9 64-bit

Setting Up an LNMP Environment on CentOS 7.9 64-bit

CentOS 7.9 64位 搭建 LNMP环境What is a LAMPLAMP is a free and open source software suite combines four po…

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…

CODE | DTH Temperature & Humid Sensor - Arduino Project 036

CODE | DTH Temperature & Humid Sensor - Arduino Project 036

The DHT11 Temperature and Humidity Sensor senses, measures and regularly reports the relative humidi…

How to use the Soldering Electric Maker Basic Technology

How to use the Soldering Electric Maker Basic Technology

如何使用电络铁?初级电子制作与维修之焊接知识Gather Tools: You will need a soldering iron, solder, a soldering iron stand,…

CODE | LED Fire Effect - Arduino Project 009

CODE | LED Fire Effect - Arduino Project 009

Project 9 will use LEDs and a flickering random light effect, via PWM again, to mimic the effect of…

CODE | Liquid Crystal Displays Autoscroll - Arduino Project 023A

CODE | Liquid Crystal Displays Autoscroll - Arduino Project 023A

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.