CODE | LED Interactive Chase Effect - Arduino Project 006

RonWang3 years ago (2023-06-17)电子编程 COD4

Leave your circuit board intact from Project 5. You’re just going to add a potentiometer to this circuit, which will allow you to change the speed of the lights while the code is running. 

项目6  交互式跑马灯Interactive Led Chase Effect

06 Interacitve LED Chase Effect Circuit and Schematic

/* Coding Ron Wang
   June 25th 2024
   Autaba support for coding hardware
 */
// Project 6 - Interactive LED Chase Effect

byte ledPin[] = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; // Create array for LED pins
int ledDelay; // delay between changes
int direction = 1;
int currentLED = 0;
unsigned long changeTime;
int potPin = 2; // select the input pin for the potentiometer
void setup() {
for (int x=0; x<10; x++) { // set all pins to output
 pinMode(ledPin[x], OUTPUT); }
 changeTime = millis();
}
void loop() {
ledDelay = analogRead(potPin); // read the value from the pot
 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 | 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…

CODE | Bollean - Arduino Programming Basic

CODE | Bollean - Arduino Programming Basic

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静…

Electronic color code

Electronic color code

An electronic color code or is used to indicate the values or ratings of electronic components, usua…

How to Selection Soldering for your Maker

How to Selection Soldering for your Maker

如何选用合适的电络铁?初级电子制作与维修之工具选择电烙铁是我们电子制作和装配中,导线、延长线连接,电子元件的安装和拆卸的必备工具。尤其是在电器维修中也是最常用的工具。电烙铁的分类电络铁的分类方式很多,…

Coding | 锻炼孩子的逻辑思维

Coding | 锻炼孩子的逻辑思维

自然语言(人类的语言)和计算机语言之间有许多相似之处,学习计算机语言类似于学习一门外语语法。 计算机编程或者算法的难点和意义是,是编程思维和解决问题能力。程序设计早已不是程序员们独有的技术活了,很多国…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.