Advice sought for timing problem

WHAT I can add to this program so that when I press a button, the arduino starts counting and if it reaches two seconds, I press the other button, an LED will light for three seconds; and that this action be repeated indefinitely

int led = 2;
int p1 = 3; // pulsador 1
int p2 = 4; // pulsador 2

const int tiempo_exacto = 1000;
int ultimo = 0;
int ultimocambio =0;
int tiempo =0;
int reset = 0;
void setup() {
pinMode(led, OUTPUT);
pinMode(p1, INPUT);
pinMode(p2, INPUT);
Serial.begin(9600);
}

void loop(){
 
 
if (digitalRead(p1) == HIGH) {
  tiempo = millis();
 if(tiempo <= tiempo_exacto){
if (digitalRead(p2) == HIGH){
    digitalWrite(led, HIGH);
    delay(3000);
    digitalWrite(led, LOW);
   
  
}}}

 
else {
  digitalWrite(led, LOW);
 
}
}

millis() returns 'unsigned long' not 'int' values so your variables need to match.

It also returns elapsed time, you you need to detect the first button transition (not the state) and capture that time and then compare the current time - start time and see if that if greater than or equal to how much time you want to wait.

Take a look at the "BlinkWithoutDelay" and "StateChangeDetection" examples in the IDE (File->Exampels->02 Digital->...)

Learning to use code tags would also be helpful.
Learning to use autoformat would also be helpful.

It helps to help those who provide free help.

WHAT I can add to this program so that when I press a button, the arduino starts counting

Starts counting what?

@PedroDest, please edit your Original Post and change the title so that people looking for this very useful Tutorial Using millis() for timing. A beginners guide will not be confused.

...R

Do not cross threads, two at the Spanish forum (were merged) and this one with the same theme.