Real time potentiometer update for neopixel strip

Hello, I’ m currently working on a project using a neopixel strip where I want to be able to control how fast the leds run through the rainbow cycle. I have everything set up correctly and the potentiometer is able to control how fast the leds move, but the strip only updates after it has completed a cycle. How can I program the strip to update as soon as I turn the potentiometer?

Here’s the code I’m currently using:

#include <Adafruit_NeoPixel.h>

// constants won't change. They're used here to 
// set pin numbers:
const int ledPin = 6;     // the number of the neopixel strip
const int numLeds = 60;
const int potPin = A5;

//Adafruit_NeoPixel pixels = Adafruit_NeoPixel(8, ledPin);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(numLeds, ledPin, NEO_GRB + NEO_KHZ800);


void setup() {
  Serial.begin(9600);
  strip.begin();
  strip.setBrightness(80); // 1/3 brightness

}

void loop() {
    Serial.print("Potentiometer value: ");
    Serial.println((analogRead(A5)/2.8));
    rainbow((analogRead(A5)/2.8));


}


void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i*1+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
    return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else {
    WheelPos -= 170;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Thanks for reading!

Simple, by stop using delay :) Have a look at blink without delay :)

When I get rid of delay, the strip ignores the potentiometer entirely. I'm looking at the blink without delay example, but don't see how I can apply it to my code

Yes of course it will ignore the pot if you remove the delay(). The delay is the only spot where you use the pot. But you have to replace the delay() (and thus the j for-loop) by a millis() based delay.