Help combining Blink w/o Delay and For Loop

I’ve been working my way slowly through various iterations of a new project and I’m finally moving towards what I really need in order to get the results that I need, the issue is that I’m struggling to combine the Blink w/o delay code with the For Loop code properly. Rather than having a fixed time (as is the case in the For Loop) example, I want to have an analog input (potentiometer) controlling the time of the stepping on/off LEDs. I’ve pasted the code below and I’m going to keep troubleshooting it, but was hoping maybe someone has insight into what I think may inevitably be a stupid oversight on my part.

Thanks in advance,
J

const int sensorPin = 2;
int sensorValue = 0;
long previousMillis = 0;
long interval = sensorValue;

void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}

void loop()
{
sensorValue = analogRead(sensorPin);
unsigned long currentMillis = millis();
{

for (int thisPin = 2; thisPin < 8; thisPin++) {

if(currentMillis - previousMillis > sensorValue) {
previousMillis = currentMillis;
if (thisPin == LOW)
thisPin = HIGH;
else
thisPin = LOW;

}
}
}
}

It isn't clear what it is you need, but it looks like the time-related stuff you've got inside your "for" loop ought to be outside it. If you're trying to what I think (i.e switch all of the LEDs on or off at the same time) then all you need is a blink without delay, but with a simple "for" loop just to set that state of ALL the LEDs.

Hi Groove,

I'm actually looking to step/blink each LED one at a time before looping back to the start and have the time each LED blinks on/off based on the potentiometer reading

I have it working with using delay(analog sensor reading), but want to be able to interrupt the sequence, which has led me to realize I need to be using something akin to the Blink w/out Delay programming instead of delay.

Sorry about the confusion, does that make more sense? The moving of the timing stuff makes sense though... thanks.

J

I think your loop is missing a "digitalWrite"

Maybe something like this

for(int ledPin=0; ledPin <= numberOfLeds; i++)
{
     unsigned long startTime = millis();  // Set the starting time
     digitalWrite(ledPin, HIGH);           //turn ON the LED
     waitingTime = (analogRead(analogPin) * factor);  //make the 0-1023 reading into a functional and appropriate delay
     while( millis < waitingTime ) ;             //do nothing while we wait
     digitalWrite(ledInUse, LOW);             //turn OFF the LED
     
}