int tempo = 1000;
int tempoPotPin = A17;
int velocity = 100;
int channel = 1;

unsigned long lastStepTime = 0;
int currentStep = 0;
int totalSteps = 8;

int ledPins[8] = { 5, 6, 7, 8, 9, 10, 11, 12 };

void setup() {

  Serial.begin(9600);

  for (int i = 0; i < totalSteps; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
}

void loop() {
  updateTempo();
  updateSequencer();
  updateLeds();
}

void updateTempo() {
  tempo = map(analogRead(A17), 0, 1023, 50, 1000);
}

void updateSequencer() {
  if (millis() > lastStepTime + tempo) {

    lastStepTime = millis();

    currentStep++;
    if (currentStep >= totalSteps) {
      currentStep = 0;
    }
  }
}

void updateLeds() {
  for (int i = 0; i < totalSteps; i++) {
    if (currentStep == i) {
      digitalWrite(ledPins[i], HIGH);
    } else {
      digitalWrite(ledPins[i], LOW);
    }
  }
}