I'm relatively new to Arduino, but I've created a chase sequence using 12 LEDs. I'm trying to use custom functions to learn about how they work. The code compiles fine and downloads to my Arduino Nano. The intent is for the LED chase to start slow and increase in speed until all LEDs stay lit before turning off and resetting for the next chase sequence. The trouble is that I have a "blip" or a "flash" happening on all LEDs just before the first LED lights in the chase sequence. I can't for the life of me explain why this is happening. Can someone please look at the code to see what I might be doing wrong? I've tried commenting the code to help show my intention. Thanks in advance for any help you may offer.
//this code is create an LED Chaser using 12 LEDs: three blue, 3 green, three yellow, and three white
//the wiring runs from Nano I/O pin to resistor; resistor is connected to LED anode; LED cathode is connected to ground
int bLED1 = 2;
int bLED2 = 3;
int bLED3 = 4;
int gLED1 = 5;
int gLED2 = 6;
int gLED3 = 7;
int yLED1 = 8;
int yLED2 = 9;
int yLED3 = 10;
int wLED1 = 11;
int wLED2 = 12;
int wLED3 = 13;
int dT = 100; //delay time
int dTchase; //delay time variable for chase function
void setup() {
// put your setup code here, to run once:
// pinModes set as outputs for LEDs
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//to call the function use: voidname();
allLEDoff(); //call function to digitalWrite all LED pins low
delay(dT);
chase(); //runs the chase function
dTchase = 125; //changes the delay variable
// the pattern continues gradually decreasing the delay so the LEDs appear to move faster
chase();
dTchase = 100;
chase();
dTchase = 83;
chase();
dTchase = 75;
chase();
dTchase = 62;
chase();
dTchase = 50;
chase();
dTchase = 38;
chase();
dTchase = 25;
chase();
dTchase = 12;
chase();
dTchase = 12;
chase();
dTchase = 8;
chase();
dTchase = 8;
chase();
dTchase = 5;
chase();
dTchase = 5;
chase();
dTchase = 4;
chase();
dTchase = 3;
chase();
dTchase = 2;
chase();
dTchase = 1;
allLEDon(); // calls the function to turn on all the LEDs
delay(3000); // holds the LEDs on
allLEDoff(); //calls the function to turn off all LEDs
delay(6000); // holds LEDs off
}
void chase() { //this is where you digital write the LED pins on and off in chase pattern
delay(dT);
digitalWrite(bLED1, HIGH);
delay(dTchase);
digitalWrite(bLED2, HIGH);
delay(dTchase);
digitalWrite(bLED3, HIGH);
delay(dTchase);
digitalWrite(gLED1, HIGH);
digitalWrite(bLED1, LOW);
delay(dTchase);
digitalWrite(gLED2, HIGH);
digitalWrite(bLED2, LOW);
delay(dTchase);
digitalWrite(gLED3, HIGH);
digitalWrite(bLED3, LOW);
delay(dTchase);
digitalWrite(yLED1, HIGH);
digitalWrite(gLED1, LOW);
delay(dTchase);
digitalWrite(yLED2, HIGH);
digitalWrite(gLED2, LOW);
delay(dTchase);
digitalWrite(yLED3, HIGH);
digitalWrite(gLED3, LOW);
delay(dTchase);
digitalWrite(wLED1, HIGH);
digitalWrite(yLED1, LOW);
delay(dTchase);
digitalWrite(wLED2, HIGH);
digitalWrite(yLED2, LOW);
delay(dTchase);
digitalWrite(wLED3, HIGH);
digitalWrite(yLED3, LOW);
delay(dTchase);
digitalWrite(wLED1, LOW);
delay(dTchase);
digitalWrite(wLED2, LOW);
delay(dTchase);
digitalWrite(wLED3, LOW);
delay(dT);
}
void allLEDon() {
digitalWrite(bLED1, HIGH);
digitalWrite(bLED2, HIGH);
digitalWrite(bLED3, HIGH);
digitalWrite(gLED1, HIGH);
digitalWrite(gLED2, HIGH);
digitalWrite(gLED3, HIGH);
digitalWrite(yLED1, HIGH);
digitalWrite(yLED2, HIGH);
digitalWrite(yLED3, HIGH);
digitalWrite(wLED1, HIGH);
digitalWrite(wLED2, HIGH);
digitalWrite(wLED3, HIGH);
}
void allLEDoff() {
digitalWrite(bLED1, LOW);
digitalWrite(bLED2, LOW);
digitalWrite(bLED3, LOW);
digitalWrite(gLED1, LOW);
digitalWrite(gLED2, LOW);
digitalWrite(gLED3, LOW);
digitalWrite(yLED1, LOW);
digitalWrite(yLED2, LOW);
digitalWrite(yLED3, LOW);
digitalWrite(wLED1, LOW);
digitalWrite(wLED2, LOW);
digitalWrite(wLED3, LOW);
}