CODE | LED Interactive Chase Effect - Arduino Project 006

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

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 | LED Traffic Light - Arduino Project 003

CODE | LED Traffic Light - Arduino Project 003

You are now going to create a set of traffic lights that will change from green to red, via amber, a…

CODE | Joystick Servo Control - Arduino Project 027

CODE | Joystick Servo Control - Arduino Project 027

In this tutorial, we are going to learn how to use Arduino and a joystick to control two servo motor…

CODE | Dual Shift Register 8-Bit Binary Counter - Arduino Project 018

CODE | Dual Shift Register 8-Bit Binary Counter - Arduino Project 018

In Project 18, you will daisy chain (or cascade) another 74HC595 IC onto the one used in Project 17…

DIY T12 Soldering (Full-Assembled Kits)

DIY T12 Soldering (Full-Assembled Kits)

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

CODE | LED Chase Lights - Arduino Project 005

CODE | LED Chase Lights - Arduino Project 005

You’re going to use a string of LEDs (10 in total) to make an LED chase effect, similar to that used…

The incredible growth of Python

The incredible growth of Python

Python is a powerful programming language and Big Scope of Python   Programming Language. Pytho…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.