Variable speed light array

Hi , trying to achieve a varying speed using a pot connected to A0.
The sketch uploaded OK , but the array seems to have decided on its own constant rate ---X milliseconds.
Any help appreciated


int potPin = A0;
int potValue;


//  LED patterns here
unsigned char led_pattern[] = {


  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
  0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f

};

void setup() {

  // set pin 2 to 5 as outputs
  for (int i = 2; i <= 5; i++) {
    pinMode(i, OUTPUT);
  }
}

void loop() {
  potValue = analogRead(potPin);
  potPin = map(A0, 0, 1023, 100, 1000);

  DisplayPattern(led_pattern, sizeof(led_pattern));
  delay(potValue);
}

void DisplayPattern(unsigned char *pattern, int num_patterns)
{
  static int pattern_num = 0; // keeps count of patterns
  unsigned char mask = 1;     // for testing each bit in pattern

  // LEDs on pin 2 to pin 5
  for (int i = 2; i <= 5; i++) {
    // check if bit in pattern is set or not and switch LED accordingly
    if (pattern[pattern_num] & mask) {
      digitalWrite(i, HIGH);
    }
    else {
      digitalWrite(i, LOW);
    }
    mask <<= 1;   // adjust mask for checking next bit in pattern
  }
  pattern_num++;  // move to next pattern for next function call
  // keep pattern within limits of pattern array
  if (pattern_num >= num_patterns) {
    pattern_num = 0;
  }
}

Don’t you want potValue in the map() function instead of A0 ?

hi , tried that but still the same.
Thanks for your reply.

If you change something to your sketch, please show the sketch.

I used the advice by @6v6gt and it works.

The change is only to the loop() and I also make the potentiometer go from turn-left-slow to turn-right-fast.

You can add extra variables to make clear what the code is doing.
So I added a variable 'delayValue' and used that for the delay. As you can see, I declare that variable in the loop().

void loop() {
  potValue = analogRead(potPin);
  int delayValue = map(potValue, 0, 1023, 1000, 100);

  DisplayPattern(led_pattern, sizeof(led_pattern));
  delay(delayValue);
}

Your array with the pattern has the numbers 0 up to 15. That means you can use a variable that counts from 0 to 15, and that will be the same as the array.

The new sketch in Wokwi simulation:

That simulator is very impressive, at least for using a design which someone else has installed, which is all I have tested.

Thank you Koepel , works a treat.
Best regards.