getting stuck in for loop using millis

I have a program that was working when using delay, but gets stuck in a for loop when switching to millis(). This is the loop that is getting stuck, I used the serial monitor and noticed it stops at 3 and doesn't increment to four.

  void Digit::display_digit(int val){
    for(int i = 0; i < 7; i++){
       int *dd_led = set_pins(val);
       Serial.print(i);
       digitalWrite(digit_led[i], dd_led[i]);
       Serial.print(i);
     }
  }

this function works everywhere else in the code and both arrays are returning the correct values.

This is the method call, start time is initialized elsewhere. I've printed the difference of cur-start and its usually somewhere around 13-20 ms. The code never gets into the if statement because it is stuck in the method d->display_digit(t->get_min()); which is shown above.

    void loop(){
       cur_time = millis();
       if(cur_time - start_time >= 1000){
         Serial.println("decremented");
         t->decrement_second();
         t->set_time(t->get_time());
         start_time = cur_time;
       }
        d->display_digit(t->get_min());
   }

.
Any help is appreciated, thanks.

Please post the complete program.

And maybe have another go at describing the problem because I don't understand it from your Original Post.

It seems to me you need debugging code inside the displayDigit() function.

A very Very VERY wild guess is that you are overwriting memory somewhere. And if so the problem might have predated the switch to millis() but was harmless because nothing useful was being overwritten.

...R

int *dd_led = set_pins(val);

if set_pins() returns stack array, then you are accessing values which are no longer valid once you exit the function.

if set_pins() returns heap memory, then you have memory leak since you never free the array.

I ended up just rewriting everything in the loop and got it to work. Still not sure why that bug appeared but It helped when I moved the cur_time = millis(); out of a state. I didn't show in the code but that segment above in the loop appeared in a state, so the millis was only getting called if it was in a particular state, maybe that had something to do with it

av197:
I didn't show in the code but that segment above in the loop appeared in a state,

That's why we always prefer to see a complete program.

...R