time should be an unsigned int. As soon as millis reaches 32768, it will be stored as -32768 in time, and your comparisons will not work. This happens after 32.768 seconds. Here's a short sketch to illustrate:
int time = 0;
void setup() {
Serial.begin( 9600 );
}
void loop() {
time = millis();
if (time % 1000 == 0) {
Serial.println( time );
delay( 2 ); // let millis() increment
}
}
To see the difference, just change the first line to
unsigned int time = 0;
Note how time rolls over to 0 after 65535 (well, only 65000 is printed).
I would recommend using unsigned constants by adding a "U" after the digits: 1000U.
Also In your if statements, this statement needs parenthesesyou must cast the millis to bethe same (smaller) type: (unsigned int)millis(). Also, parentheses make the expression more clear:
else if (((unsigned int)millis() - time > 1000U) && ((unsigned int)millis() - tempo < 2000U)) {digitalWrite(led_2, HIGH);}