当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 005 - LED Chase Lights

RonWang6个月前 (06-18)电子编程110

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;}
}

版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://parentscn.com/?id=255

标签: Arduino

相关文章

Arduino Project 011 - Piezo Sounder Alarm

Arduino Project 011 - Piezo Sounder Alarm

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

​Arduino Project 046 - Based Security System by Arduino with Lcd Display

​Arduino Project 046 - Based Security System by Arduino with Lcd Display

Arduino Project 046 - Based Security System by Arduino with Lcd Display/*  * Project ...

Arduino Project 007 - Pulsating Lamp

Arduino Project 007 - Pulsating Lamp

You are now going try a more advanced method of controlling LEDs. So far, you have simply turned the...

Arduino Project 036 - DTH Temperature and Humid Sensor

Arduino Project 036 - DTH Temperature and Humid Sensor

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

Arduino Project 026 - Dual Servo Control

Arduino Project 026 - Dual Servo Control

This project you’ll create another simple project, but this time you’ll control two servos using com...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。