Topic: Audio Signal Direction Detection
Hello, what do you think of this arduino code in regards to understandability, optimization and size?
Any suggestions for improvements?

void cycleLEDs(int interval) {
  const int nOutPins = sizeof(outPins) / sizeof(outPins[0]);
  static unsigned long lastChange = 0;
  static int currIndex = 0; // Use static to retain value between function calls
  int nextIndex = 0;
  
  if (millis() >= lastChange + abs(interval)) {

    // Determine direction
    int direction = interval < 0 ? -1 : 1;

    // Update secondary index
    nextIndex = currIndex + direction;
    if (nextIndex < 0) {
      nextIndex = nOutPins - 1;
    } else if (nextIndex >= nOutPins) {
      nextIndex = 0;
    }
    
    // Turn off all LEDs
    for (int i = 0; i < nOutPins; i++) {
      if (i == currIndex || i == nextIndex){
        digitalWrite(outPins[i], HIGH);
      } else {
        digitalWrite(outPins[i], LOW);
      }      
    }

    // Update current index
    currIndex += direction;
    if (currIndex < 0) {
      currIndex = nOutPins - 1;
    } else if (currIndex >= nOutPins) {
      currIndex = 0;
    }

    // Update timer
    lastChange = millis();
  }
}

Thank you for your help, i value your input.

Topic: Audio Signal Direction Detection
find the issue: #include "mbed.h"
#include <exception>

DigitalOut ledYellow(D2);
DigitalOut ledAmber(D3);
DigitalOut ledRed(D4);

Thread thread2;
Thread thread3;

int counter = 0;

// Subroutine for any LEDs
void ledAny (DigitalOut *ledA){
    while(true){
        *ledA = 1;
        ThisThread::sleep_for(500ms);
        *ledA =0;
        ThisThread::sleep_for(1500ms);
        printf("My pointer is %p\n", *ledA);
    }
}


// main() runs in its own thread in the OS
int main(){

    thread2.start(callback(ledAny, &ledYellow));
    ThisThread::sleep_for(1000ms);
    thread3.start(callback(ledAny, &ledAmber));

    while (true) {
        counter = counter + 1;

        ledRed.write(true);
        ThisThread::sleep_for(500ms);
        ledRed.write(false);
        ThisThread::sleep_for(500ms);

        if (counter>20){
            thread2.terminate();
        }


    }
}