I put the code into my hack for neopixels, and I noticed that t1 was never used. I did find a place for it where the new soldier is given a moment of his own, or the remaining soldiers are so paused over.
The time constants are small so it is hard to see what is really going on.
Well, that doesn't say me too much, but if you would paste here a full code I just can paste it into my A_IDE I would love to try it out and think on it a bit. I love to learn However, I have a lot of work on the hardware now, I am just testing fixing one of my circuits that gives me a hard time as well
Without this, and other hardwares the project would never be alive
Thanks a lot, guys!
Please try this with 9 LEDs attached to pins 2..10.
It... does what you wanted. There is an odd partial symmetry between marching on and marching off. I had some trouble until I focused and just ran all the loops from 0 and fixed LED references accordionly.
It uses delay, so blocks, switching it to the unblocking style would be
Making it go backwards could be done by making the LED pin array a variable the functions could use, so providing an array with the LEDs in reverse order would be Presto! backwards.
Summary
// https://wokwi.com/projects/391667794741666817
// https://forum.arduino.cc/t/built-in-and-out-led-effect-direction-help/1230282
# define SIZE 9
byte pins[9] = {2, 3, 4, 5, 6, 7, 8, 9, 10};
# define t0 200
# define t1 400
# define t2 800
void setup() {
Serial.begin(115200);
Serial.println("for loop version N\n");
for (int ix = 0; ix < SIZE; ix++)
pinMode(pins[ix], OUTPUT);
}
void loop() {
fileOnLeft();
fileOffRight();
}
// turn on from the left starting from all off
void fileOnLeft()
{
for (int ix = 0; ix < SIZE; ix++) {
byte K = SIZE - 1;
for (int iy = 0; iy < SIZE - ix; iy++) {
digitalWrite(pins[K - iy], HIGH);
delay(t0);
digitalWrite(pins[K - iy], LOW);
}
digitalWrite(pins[ix], HIGH);
delay(t1);
}
delay(t2);
}
// turn off from the right starting from all on
void fileOffRight()
{
for (int ix = 0; ix < SIZE; ix++) {
byte K = ix - 1;
digitalWrite(pins[ix], LOW);
for (int iy = 0; iy < ix; iy++) {
digitalWrite(pins[K - iy], HIGH);
delay(t0);
digitalWrite(pins[K - iy], LOW);
}
delay(t1);
}
delay(t2);
}