How to reset millis()

Hi I need help please, I need to reset the period in order to restart the code

#include <Servo.h>

// Declaramos la variable para controlar el servo
Servo servoMotor;
unsigned long startMillis;  //some global variables available anywhere in the program
unsigned long currentMillis;
 const unsigned long period = 60000;

void setup() {
  // Iniciamos el monitor serie para mostrar el resultado
  Serial.begin(9600);

  // Iniciamos el servo para que empiece a trabajar con el pin 9
  servoMotor.attach(9);
  
  startMillis = millis();
}

void loop() {
  currentMillis = millis();
 
  
if (currentMillis - startMillis == period){
  
  
  servoMotor.write(0);
  
  delay(1000);
  
  servoMotor.write(90);
 
  delay(1000);

 
  }

   

  
  }

I think you can get what you ask by simply updating "startMillis" at each successful compare:

void loop() 
{
    currentMillis = millis();
 
    if (currentMillis - startMillis >= period)
    {
        startMillis = currentMillis;
        servoMotor.write(0);
        delay(1000);
        servoMotor.write(90);
        delay(1000);
 
    }

}

BTW, don't use "==" for millis() compares; use greater/less than operators to be sure you don't miss anything if the micro's attention is hogged by something and millis() ticks past your target value.

BTW, why use delays() inside a millis()-timed event?

(Edited to fix "startMillis" within if statement)

Blackfin:
I think you can get what you ask by simply updating "startMillis" at each successful compare:

void loop() 

{
    currentMillis = millis();

if (currentMillis - startMillis >= period)
    {
        stateMillis = currentMillis;
        servoMotor.write(0);
        delay(1000);
        servoMotor.write(90);
        delay(1000);

}

}




BTW, don't use "==" for millis() compares; use greater/less than operators to be sure you don't miss anything if the micro's attention is hogged by something and millis() ticks past your target value.

BTW, why use delays() inside a millis()-timed event?

Thank you
And its because I'm trying to push a dispenser

That's a good enough reason. But throw away the second delay. That does nothing.

It is silly to mix delay() and millis() in the same code. If it is important to turn something on periodically, without using delay(), then it is equally important to turn if off later, without using delay().

The demo Several Things at a Time illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

It should never be necessary to reset millis(). You don't reset your kitchen clock before you start cooking a roast chicken :slight_smile:

...R