millis() for shared tasks

I am working with arduino one, the robot uses two motors, two encoder, one servo, one color sensor, one button, and one 8x2 lcd.
The sending of serial data to the lcd is made by pin 13, I want the animation to work in an infinite loop as long as the button is not pressed. With my code, the animation is performed, but it is not repeated, it is returned to the first line, which contains the "eyes closed" function,

In the first sketch,
I put the following code:

If (millis () - time1 >=1000){

But sync errors occurred
For this reason place the compound operators and aritmetic operator, this way:

If (millis () + time1 == 1000){

I would like the animation of the lcd to be made in infinite loop, if the button is not pressed

Code fragment:

unsigned long time1 = 0
unsigned long time2 = 0
unsigned long time3 = 0

void setup ()
{
//and the rest of the code...
}
void loop()
{
while (b.isReleased()){
void eyesFunction ();

}
//and the rest of the code...

void eyesFunction (){

If (millis () + time1 == 1000){
open_Eyes();
time1 = millis();
}
If (millis () + time2 == 1500){
closed_Eyes();
time2 = millis();
}
If (millis () + time3 == 2000){
happy _Eyes();
time3 = millis();

//etc....
}}

Please i would like your help

sonicaction:
With my code, the animation is performed, but it is not repeated, it is returned to the first line, which contains the "eyes closed" function,

In the first sketch,
I put the following code:

If (millis () - time1 >=1000){

But sync errors occurred
For this reason place the compound operators and aritmetic operator, this way:

If (millis () + time1 == 1000)

You've changed two things there. You've changed ">=" to "==" and "-" to "+".

You definitely want to stick with "-" there to calculate elapsed time.

There are other problems with the timing logic but I don't have time to address them right now.

Show us your current sketch, all code. Please use code tags. Use the </> icon in the posting menu. [code] Paste sketch here. [/code]

'If' is not the same as 'if'
If (millis () + time1 == 1000){ // == will only happen if 'equal' may not even see this when code runs.

stuart0:
There are other problems with the timing logic but I don't have time to address them right now.

Ok I will really briefly.

I think that what you really want there is to store just one base time (eg time1), and to time your events from that. As in:

"if (milis()-time1 ==1000)" {do something}
"if (milis()-time1 ==1500)" {do something else}
"if (milis()-time1 ==2000)" {time1 = millis() and do something else}

Also, you can use >= instead of == if you're worried about perhaps missing an event. In this case however then you might need to store a flag so that you know that the task has been performed and don't keep repeating it.

In loop, this:

void eyesFunction ();

Should be:

eyesFunction ();

Dispite some errors try this code

// define state as byte
byte state = 0;

void eyesFunction (){ 
  switch (state) {
       case 0:  open_Eyes();
                if (millis() - time1 > 1000) {
                   time1 = millis();
                   state = 1;
                   break;
                }
        case 1: close_Eyes();
                if (millis () - time2 : 1500) {
                   time2 = millis();
                   state = 2;
                   break;
                }  
                break;
        case 2: happy_Eyes();
                If (millis () - time3 > 2000) {
                    time3 = millis();
                    state = 0;
                }
                break;
  }
}

But there is a little problem. Your code calls eyesFunction during 1000 mseg doing nothing.
My suggestion starts with open_Eyes() during 1000 mseg and follows with the other two states.

The demo Several Things at a Time is an extended example of BWoD and illustrates the use of millis() to manage timing. It may help with understanding the technique.

...R