// https://www.instructables.com/LED-Chase-Effect-Using-an-Arduino/
#define potentiometer A7
//#define debug
int read_ADC, delay_time;
int leds[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
// https://www.arduino.cc/reference/en/language/variables/utilities/sizeof/
// sizeof(); https://forum.arduino.cc/t/how-do-you-check-the-length-of-an-array/88325/7
int total_leds = sizeof(leds) / sizeof(int); // enter the number of LEDs you want to use here
int ledDelay(100);
int direction = 1;
int currentLED;
unsigned long changeTime;
void setup() {// put your setup code here, to run once
Serial.begin(9600);// initialize serial communication at 9600 bits per second:
#ifdef debug
Serial.println("Debug Enabled");
#else
Serial.println("Debug Disabled");
#endif
for (int i = 0; i < total_leds; i++) {
pinMode(leds[i], OUTPUT); // declare LEDs as output
}
// changeTime = millis();
}
//this function for texting only
void loop() {
if ((millis() - changeTime) > ledDelay) {
changeLED();
changeTime = millis();
}
}
void changeLED() {
allLedsOff();
currentLED += direction;
if (currentLED == -1) {
direction = 1;
}
else if (currentLED == total_leds) {
direction = -1;
}
digitalWrite(leds[currentLED], HIGH);
}
void allLedsOff() {
for (int x = 0; x < total_leds; x++) {
digitalWrite(leds[x], LOW);
}
}