which timer do I have to use to chorno between 2 led blink

which timer do I have to use to chorno between 2 led blink
so if I want to chrono the time between two led HIGH.
Which code do I have to use

blink without delay ?

Mark

long startTime ;                    // start time for stop watch
long elapsedTime ;
int preincrementation = 8;
int vrai = 9;


float prevtension;// global variables are retained on each iteration of loop()
long time;
int valeurLue;

int analogPin = A0;
const int led =  13; 
float tension; //variable pour stocker la valeur lue après conversion


void setup() {
  pinMode(analogPin, INPUT);
  pinMode( led, OUTPUT ); 
  digitalWrite(led, HIGH); 
  delay (500);
  digitalWrite(led, LOW); // 2.5cm
  Serial.begin(115200);

}



void loop() {
  prevtension = tension;

  valeurLue = analogRead(analogPin);

  //on traduit la valeur brute en tension (produit en croix)
  tension = valeurLue * 5.0 / 1024;
  long RPMactuel = 60000000  / elapsedTime;
  long initime = 0.3 * elapsedTime;
  long RPMconsigne = 3000;
  long consigne = 60000000 / RPMconsigne;

  if (tension < 2.8)
  {
    if (tension < (prevtension - 0.005)) {  // compare them
      elapsedTime =   millis() - startTime;   
      startTime = millis(); 
      digitalWrite(led, HIGH); 

      if(elapsedTime > consigne)
      {
        time = initime;
      } // 4%

      if(elapsedTime < consigne)
      {
        time = 4;
        if ( (consigne - (consigne * 0.02)) < elapsedTime < (consigne + (consigne * 0.02)))
          digitalWrite (preincrementation, HIGH);
        { 
          if ( elapsedTime < consigne )
          {

            if ( elapsedTime > (consigne - (consigne * 0.0001)) )
            {
              time = 4;
              time += 0.001;
            }
            if ( elapsedTime < (consigne + (consigne * 0.0001)) )
            {
              time = 4;
              time -= 0.001;
            }

            if ((consigne - (consigne * 0.0001)) < elapsedTime < (consigne + (consigne * 0.0001)))
            {
              digitalWrite (vrai, HIGH);
            }
          }   
        }

        delay (time);
        digitalWrite(led, LOW); // do something, they are different
        {
        } 
      }
    }
  }



  Serial.print("elapsedTime = ");
  Serial.println(elapsedTime);
  Serial.print("consigne = ");
  Serial.println(consigne);
  Serial.print("rpm actuel = ");
  Serial.println(RPMactuel);
  Serial.print("rpm consigne = ");
  Serial.println(RPMconsigne);
  Serial.print("initime = ");
  Serial.println(initime);
  Serial.print("time = ");
  Serial.println(time);
  Serial.print("tension = ");
  Serial.println(tension);



  Serial.println();
  Serial.println();

}

hi I want to calculate the time between my led High until the second led High

What does chorno/chrono mean?

Could you just count the milliseconds which have elapsed?

yeah chrono means timer sorry

millis() or micros().
example to make 2 LEDs blink at different frequencies

void loop(){
currentMillis= millis(); // capture the 'time'
elapsedMillis1 = currentMillis - previousMillis1; // see how much time has passed
if (elapsedMillis1 >= duration1) // enough passed for LED1?
{
previousMillis1 = previousMillis1 + duration1; // capture time for the next change
if (LEDstate1 == HIGH){LEDstate1 = LOW);} // change the level to use for the LED
else {LEDstate1 = HIGH;}
digitalWrite (LED1pin, LED1state1); // write the new LED level to the pin
 }

// similar for LED2
elapsedMillis2 = currentMillis - previousMillis2;
if (elapsedMillis2 >= duration2){
previousMillis2 = previousMillis2 + duration2;
if (LEDstate2 == HIGH){LEDstate2 = LOW);}
else {LEDstate2 = HIGH;}
digitalWrite (LED2pin, LED1state2);
 }

} // end loop

Declare all time related variables as unsigned long.
Check the { }s, I think I have them paired correctly.
Use CTRL-T to make it look neater.

Are the LEDs controlled by your code, or by something external?
If your code, then you control when they switch - use similar to what I posted to control when one turns and then other turns on.

ok thank you but if i understand it good
it means that to calculate the time between to events i have to use the code that you gave me with previous and current ?

yeah the leds are in the code but how are they declared ? equal to zero or ???

Yes, that is one way if your code is controlling the start & stop times.

If you are attempting to measure (calculate) the times of events that are not under your control:
Start the timer when one event occurs (signal goes high) and stop when the second event occurs (goes high):

void loop(){
if (timerRunning == 0 && digitalRead(input1) == HIGH){ // assumes the first signal is low to start with
startTime = millis();
timerRunning = 1; // use a 'flag' to keep track of whether a measurement is going on
}
if ( timerRunning == 1 && digitalRead (input2) == HIGH){ // waiting for 2nd to go high
endTime = millis();
timerRunning = 0;
elapsedTime = endTime - startTime;
Serial.print ("time between events (mS): ");
Serial.println (elapsedTime);
  }
}

You can use LEDstate = 0, 1, HIGH, LOW.
Then to turn them on or off
digitalWrite (LEDpin, 0); // or 1, or HIGH, or LOW. Maybe even true, false (no caps).

long currentMillis ;                    // start time for stop watch
long previousMillis ;
long elapsedMillis ;
int preincrementation = 8;
int vrai = 9;


float prevtension;// global variables are retained on each iteration of loop()
long time;
int valeurLue;

int analogPin = A0;
const int led =  13; 
float tension; //variable pour stocker la valeur lue après conversion


void setup() {
  pinMode(analogPin, INPUT);
  pinMode( led, OUTPUT ); 
  digitalWrite(led, HIGH); 
  delay (500);
  digitalWrite(led, LOW); // 2.5cm
  Serial.begin(115200);

}



void loop() {
  prevtension = tension;

  valeurLue = analogRead(analogPin);

  //on traduit la valeur brute en tension (produit en croix)
  tension = valeurLue * 5.0 / 1024;
  long RPMactuel = 60000000  / elapsedMillis;
  long initime = 0.3 * elapsedMillis;
  long RPMconsigne = 3000;
  long consigne = 60000000 / RPMconsigne;

  if (tension < 2.8)
  {
    if (tension < (prevtension - 0.005)) {  // compare them
       
     previousMillis = currentMillis;
elapsedMillis = currentMillis - previousMillis; // see how much time has passed
     currentMillis= micros(); // capture the 'time'
      digitalWrite(led, HIGH); 

      if(elapsedMillis > consigne)
      {
        time = initime;
      } // 4%

      if(elapsedMillis < consigne)
      {
        time = 4;
        if ( (consigne - (consigne * 0.02)) < elapsedMillis < (consigne + (consigne * 0.02)))
          digitalWrite (preincrementation, HIGH);
        { 
          if ( elapsedMillis < consigne )
          {

            if ( elapsedMillis > (consigne - (consigne * 0.0001)) )
            {
              time = 4;
              time += 0.001;
            }
            if ( elapsedMillis < (consigne + (consigne * 0.0001)) )
            {
              time = 4;
              time -= 0.001;
            }

            if ((consigne - (consigne * 0.0001)) < elapsedMillis < (consigne + (consigne * 0.0001)))
            {
              digitalWrite (vrai, HIGH);
            }
          }   
        }

        delayMicroseconds (time);
        digitalWrite(led, LOW); // do  something, they are different
        {
        } 
      }
    }
  }

  Serial.print("elapsedMillis = ");
  Serial.println(elapsedMillis);
  Serial.print("currentMillis = ");
  Serial.println(currentMillis);
  Serial.print("previousMillis = ");
  Serial.println(previousMillis);
  Serial.print("consigne = ");
  Serial.println(consigne);
  Serial.print("rpm actuel = ");
  Serial.println(RPMactuel);
  Serial.print("rpm consigne = ");
  Serial.println(RPMconsigne);
  Serial.print("initime = ");
  Serial.println(initime);
  Serial.print("time = ");
  Serial.println(time);
  Serial.print("tension = ");
  Serial.println(tension);



  Serial.println();
  Serial.println();

}

Hi everyone i have a problem my code is not working good he is not calculated the elapsed time

declare as unsigned long:
long currentMillis ; // start time for stop watch
long previousMillis ;
long elapsedMillis ;
long RPMactuel = 60000000 / elapsedMillis;
long initime = 0.3 * elapsedMillis;
long RPMconsigne = 3000;
long consigne = 60000000 / RPMconsigne;

Order is not correct here:
previousMillis = currentMillis;
elapsedMillis = currentMillis - previousMillis; // see how much time has passed << this will always be zero because the prior line made them the same value
currentMillis= micros(); // capture the 'time'

Re-read my example & understand the logic flow better.

 previousMillis = currentMillis;
elapsedMillis = currentMillis - previousMillis; // see how much time has passed
currentMillis= micros(); // capture the 'time'

the way you set it up elapsedMillis is allways zero!

 previousMillis = micros(); // starting point

*/
lots of stuff happens here (no idea what your code does)
/*

currentMillis = micros(); //end point of time measurement
elapsedMillis = currentMillis - previousMillis; // see how much time has passed (comparing the two)

EDIT: Its sort of confusing that you use micros, but your variables are called millis ...

long currentMillis  ;                    // start time for stop watch
long previousMillis ;
long elapsedMillis ;
int preincrementation = 8;
int vrai = 9;


float prevtension;// global variables are retained on each iteration of loop()
long time;
int valeurLue;

int analogPin = A0;
const int led =  13; 
float tension; //variable pour stocker la valeur lue après conversion


void setup() {
  pinMode(analogPin, INPUT);
  pinMode( led, OUTPUT ); 
  digitalWrite(led, HIGH); 
  delay (500);
  digitalWrite(led, LOW); // 2.5cm
  Serial.begin(115200);

}



void loop() {
  prevtension = tension;

  valeurLue = analogRead(analogPin);

  //on traduit la valeur brute en tension (produit en croix)
  tension = valeurLue * 5.0 / 1024;
  long RPMactuel = 60000000  / elapsedMillis;
  long initime = 0.3 * elapsedMillis;
  long RPMconsigne = 3000;
  long consigne = 60000000 / RPMconsigne;

  if (tension < 2.8)
  {
    if (tension < (prevtension - 0.005)) {  // compare them
      currentMillis = micros(); //end point of time measurement
      elapsedMillis = currentMillis - previousMillis;
      previousMillis = micros(); // starting point
      digitalWrite(led, HIGH); 

      if(elapsedMillis > consigne)
      {
        time = initime;
      } // 4%

      if(elapsedMillis < consigne)
      {
        time = 4;
        if ( (consigne - (consigne * 0.02)) < elapsedMillis < (consigne + (consigne * 0.02)))
          digitalWrite (preincrementation, HIGH);
        { 
          if ( elapsedMillis < consigne )
          {

            if ( elapsedMillis > (consigne - (consigne * 0.0001)) )
            {
              time = 4;
              time += 0.001;
            }
            if ( elapsedMillis < (consigne + (consigne * 0.0001)) )
            {
              time = 4;
              time -= 0.001;
            }

            if ((consigne - (consigne * 0.0001)) < elapsedMillis < (consigne + (consigne * 0.0001)))
            {
              digitalWrite (vrai, HIGH);
            }
          }   
        }

        delayMicroseconds (time);
        digitalWrite(led, LOW); // do something, they are different
        {
        } 
      }
    }
  }



  Serial.print("elapsedMillis = ");
  Serial.println(elapsedMillis);
   Serial.print("currentMillis = ");
  Serial.println(currentMillis);
   Serial.print("previousMillis = ");
  Serial.println(previousMillis);
    Serial.print("consigne = ");
  Serial.println(consigne);
  Serial.print("rpm actuel = ");
  Serial.println(RPMactuel);
  Serial.print("rpm consigne = ");
  Serial.println(RPMconsigne);
  Serial.print("initime = ");
  Serial.println(initime);
  Serial.print("time = ");
  Serial.println(time);
Serial.print("tension = ");
  Serial.println(tension);



  Serial.println();
  Serial.println();

}

hi everyone I want my code to time the time between high and high but its not working well can you plz help me

please define what is not working. as in, what is happening and what do you expect to happen?

there may be an issue about where/when you are declaring your variables. i.e. the first time the loop executes you don't have enough information to do the timing properly.

long currentMillis  ;                    // start time for stop watch
long previousMillis ;
long elapsedMillis ;
int preincrementation = 8;
int vrai = 9;


float prevtension;// global variables are retained on each iteration of loop()
float time;
int valeurLue;

int analogPin = A0;
const int led =  13; 
float tension; //variable pour stocker la valeur lue après conversion


void setup() {
  pinMode(analogPin, INPUT);
  pinMode( led, OUTPUT ); 
  digitalWrite(led, HIGH); 
  delay (500);
  digitalWrite(led, LOW); // 2.5cm
  Serial.begin(115200);

}



void loop() {
  prevtension = tension;

  valeurLue = analogRead(analogPin);

  //on traduit la valeur brute en tension (produit en croix)
  tension = valeurLue * 5.0 / 1024;
  long RPMactuel = 60000000  / elapsedMillis;
  long initime = 0.05 * elapsedMillis;
  long RPMconsigne = 3000;
  long consigne = 60000000 / RPMconsigne;
long petit = consigne - (consigne * 0.02);
long grand = consigne + (consigne * 0.02);



  if (tension < 2.8)
  {
    if (tension < (prevtension - 0.005)) {  // compare them
      currentMillis = micros(); //end point of time measurement
      elapsedMillis = currentMillis - previousMillis;
      previousMillis = micros(); // starting point
      digitalWrite(led, HIGH); 

      if(elapsedMillis > consigne)
      {
        time = initime;
      } 

      if(elapsedMillis < consigne)
      {
        time = 3;
        if ( petit < elapsedMillis < grand )
          digitalWrite (preincrementation, HIGH);
        { 
          if ( elapsedMillis < consigne )
          {

            if ( elapsedMillis > (consigne - (consigne * 0.0001)) )
            {
              
              time += 0.1;
            }
            if ( elapsedMillis < (consigne + (consigne * 0.0001)) )
            {
            
              time -= 0.1;
            }

            if ((consigne - (consigne * 0.0001)) < elapsedMillis < (consigne + (consigne * 0.0001)))
            {
              digitalWrite (vrai, HIGH);
            }
          }   
        }

        delayMicroseconds (time);
        digitalWrite(led, LOW); // do something, they are different
        {
        } 
      }
    }
  }

  Serial.println();
  Serial.println();

  Serial.print("elapsedMillis = ");
  Serial.println(elapsedMillis);
  Serial.println();


Serial.print("consigne = ");
  Serial.println(consigne);
Serial.print("grand = ");
  Serial.println(grand);
Serial.print("petit = ");
  Serial.println(petit);
Serial.println();



  Serial.print("currentMillis = ");
  Serial.println(currentMillis);
  Serial.print("previousMillis = ");
  Serial.println(previousMillis);
  Serial.println();



  Serial.print("rpm actuel = ");
  Serial.println(RPMactuel);
  Serial.print("rpm consigne = ");
  Serial.println(RPMconsigne);
  Serial.println();

  Serial.print("initime = ");
  Serial.println(initime);
  Serial.print("time = ");
  Serial.println(time);
  Serial.println();

  Serial.print("tension = ");
  Serial.println(tension);


  Serial.println();
  Serial.println();
  Serial.println();
  Serial.println();

}

Hi how to decrement or increment the time...

now it's just decrementing 1 time so its only going to 2.9

I can't quite figure what you're trying to do in your program, and the question makes little sense :
You've choosen a nonstandard way to represent time (float) and that's fine, but I dont know what the 0.1 increment/decrement represents (seconds?). but I do not see what stops yuo from writing time += 0.001 or any other value. Which would answer the question.

There is a small error

long RPMactuel = 60000000  / elapsedMillis;

Should be

long RPMactuel = 60000000L / elapsedMillis;

otherwise you will not get the correct starting value. Do this 'L' whenever you involve an integer constant with a long.

1st. Stop opening new topics for the same subject.
2nd. Your logic is not correct yet.

Review when you capture the start time and end time. Perhaps use a flag to indicate that time measurement is underway and don't recapture the start time when time is being measured.

Also: all time related variables should be unsigned long.

ok but its not for the same topic i solved thi sone now i have a question about decrement