CODE | LED Chase Lights - Arduino Project 005

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

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

CODE | Servo Control - Arduino Project 025

CODE | Servo Control - Arduino Project 025

You will need to obtain a standard RC servo; any of the small or mid-sized servos will do. Larger se…

About Arduino Resources

About Arduino Resources

The Arduino platform benefits from an active user community that makes it easy to get help from fell…

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 | Simple Ultrasonic Range HC-SR04 - Arduino Project 038

CODE | Simple Ultrasonic Range HC-SR04 - Arduino Project 038

Ultrasonic range finders measure distance by emitting a pulse of ultrasonic sound that travels throu…

About Arduino WIKI

About Arduino WIKI

Arduino (/ɑːrˈdwiːnoʊ/) is an open-source hardware and software company, project, and user community…

DIY T12 Soldering (Full-Assembled Kits)

DIY T12 Soldering (Full-Assembled Kits)

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

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.