To restart if equal to x

int led = 13; // Alimentation de la bobine
int hall = A0; // Analyse du capteur a effet Hall
long startTime  = 0;                    // start time for stop watch
long elapsedTime = 0 ;



unsigned long valeur; //Donnees directes du capteru a effet Hall
float tension; // Valeur actuelle en voltage du capteur
float pretension; //  Valeur precedente en voltage du capteur

void setup() // Effectuer une seule fois
{
  pinMode (hall, INPUT); // Declarer capteur a effet Hall comme INPUT
  pinMode (led, OUTPUT); // Declarer led comme OUTPUT
  digitalWrite(led, HIGH); 
  delay (20);
  digitalWrite(led, LOW);
  Serial.begin (38400); // Vitesse du retour des donnees
}


void loop() // Effectuer à chaque fois
{
  pretension = tension; // Tension precedente vs tension actuelle
  valeur = analogRead (hall); // Lecture du capteur a effet Hall
  tension = valeur * 5.0 / 1024; // Formule de calcul du voltage du capteur a effet Hall
  long RPMactuel = 60000000  / elapsedTime;
  long time = (0.1* elapsedTime)/1000;

  if (pretension == tension)
  { 
    valeur = analogRead (hall);
    tension = valeur * 5.0 / 1024;  
    digitalWrite(led, HIGH); 
    delay (20);
    digitalWrite(led, LOW);
  }

  if (2.50 < tension && tension < 2.95)
  {
    if (tension < (pretension - 0.005)) {  // compare them
      elapsedTime =   (micros() - startTime) + 20000;   
      startTime = micros(); 
      digitalWrite(led, HIGH); 
      delay (time);
      digitalWrite(led, LOW); // do something, they are different
      while (2.50 < tension && tension < 2.95)
      {
        valeur = analogRead (hall);
        tension = valeur * 5.0 / 1024;
        digitalWrite(led, LOW);
      }

    } 
  }

  if (time == 0)
  { 
    valeur = analogRead (hall);
    tension = valeur * 5.0 / 1024;
    digitalWrite(led, HIGH); 
    delay (20);
    digitalWrite(led, LOW);
  }

  Serial.print("elapsedTime= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(elapsedTime);
  Serial.print("tension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(tension);	
  Serial.print("pretension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(pretension);	
  Serial.print("RPMactuel= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(RPMactuel);	
  Serial.print("time= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(time);




  Serial.println();  // Sauter une ligne lors de l'affichage
  Serial.println();
}

I am trying to make my code digital write for 20 milliseconds if tension = pretension but it s never working

  if (2.50 < tension && tension < 2.95) Silly bit of code and to have twice. Layout your code!

Mark

what do you mean by layout

int led = 13; // Alimentation de la bobine
int hall = A0; // Analyse du capteur a effet Hall
long startTime  = 0;                    // start time for stop watch
long elapsedTime = 0 ;



unsigned long valeur; //Donnees directes du capteru a effet Hall
float tension; // Valeur actuelle en voltage du capteur
float pretension; //  Valeur precedente en voltage du capteur

void setup() // Effectuer une seule fois
{
  pinMode (hall, INPUT); // Declarer capteur a effet Hall comme INPUT
  pinMode (led, OUTPUT); // Declarer led comme OUTPUT
   digitalWrite(led, HIGH); 
      delay (20);
      digitalWrite(led, LOW);
  Serial.begin (38400); // Vitesse du retour des donnees
}


void loop() // Effectuer à chaque fois
{
  pretension = tension; // Tension precedente vs tension actuelle
  valeur = analogRead (hall); // Lecture du capteur a effet Hall
  tension = valeur * 5.0 / 1024; // Formule de calcul du voltage du capteur a effet Hall
long RPMactuel = 60000000  / elapsedTime;
long time = 0.1* elapsedTime;
long equal = (tension - pretension == 0);




  if (2.50 < tension && tension < 2.95)
  {valeur = analogRead (hall);
tension = valeur * 5.0 / 1024;
    if (tension < (pretension - 0.005)) {  // compare them
     valeur = analogRead (hall);
tension = valeur * 5.0 / 1024;
      elapsedTime =   (micros() - startTime) + 20000;   
      startTime = micros(); 
      digitalWrite(led, HIGH); 
      delayMicroseconds (time);
      digitalWrite(led, LOW); // do something, they are different
while (2.50 < tension && tension < 2.95)
{
valeur = analogRead (hall);
tension = valeur * 5.0 / 1024;
digitalWrite(led, LOW);    } 
  }
  }
  Serial.print("elapsedTime= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(elapsedTime);
  Serial.print("tension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(tension);	
     Serial.print("pretension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(pretension);	
   Serial.print("RPMactuel= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(RPMactuel);	
     Serial.print("time= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(time);




  Serial.println();  // Sauter une ligne lors de l'affichage
  Serial.println();
}

if I use delay
      delay (time); it works but delayMicroseconds it s not working

what do you mean by layout

Well, the
crazy
indentation makes
your. code
really. hard to
read.

I'm surprised you haven't noticed.
(Another corker of a topic title, BTW)

      elapsedTime =   (micros() - startTime) + 20000;

Bullshit. If elapsedTime is supposed to represent an interval, then adding 20 milliseconds to it makes no sense.

You have been asked more than once to use Tools + Auto Format before posting code. Do NOT post code again with cleaning up your piss poor indenting.

and a million microseconds in a second.

but delayMicroseconds it s not working

How would you be able to tell?

Thank you awol I forgot

and my question is why in delay it works but not in delayMicorseconds

BTW, do you seriously think we don't notice a cross-post (about which you have already been warned several times), just because it has a different title?

but the other one is about microseconds and this one is about such a sprecial blink even if not all the condition are true

It’s still the same code, so doesn’t warrant multiple posts. Also, you and your friend John have posted this code at least 5 times, perhaps with different questions, but as far as I can see, you haven’t even changed the errors from the original post. This forum is not here to do your’s and John’s homework assignments. Quit posting and start debugging. Google is your friend.

Yeah that true but I changed a lot I don<t know how you can<t see that but sometimes I read everything and it still not work
for example I am trying to write a code that will blink the led if tension is equal to pretension and it<s not working I have been working on this part since yesterday.

int led = 13; // Alimentation de la bobine
int hall = A0; // Analyse du capteur a effet Hall
long startTime  = 0;                    // start time for stop watch
long elapsedTime = 0 ;
long time;


unsigned long valeur; //Donnees directes du capteru a effet Hall
float tension; // Valeur actuelle en voltage du capteur
float pretension; //  Valeur precedente en voltage du capteur

void setup() // Effectuer une seule fois
{
  pinMode (hall, INPUT); // Declarer capteur a effet Hall comme INPUT
  pinMode (led, OUTPUT); // Declarer led comme OUTPUT
  digitalWrite(led, HIGH); 
  delay (20);
  digitalWrite(led, LOW);
  Serial.begin (38400); // Vitesse du retour des donnees
}


void loop() // Effectuer à chaque fois
{
  pretension = tension; // Tension precedente vs tension actuelle
  valeur = analogRead (hall); // Lecture du capteur a effet Hall
  tension = valeur * 5.0 / 1024; // Formule de calcul du voltage du capteur a effet Hall
  long RPMactuel = 60000000  / elapsedTime;
  long initime = (0.1* elapsedTime)/1000;
  long RPMconsigne = 3000;
  long consigne = 60000000 / RPMconsigne;

  if (pretension == tension)
  { 
    valeur = analogRead (hall);
    tension = valeur * 5.0 / 1024;  
    digitalWrite(led, HIGH); 
    delay (20);
    digitalWrite(led, LOW);
  }

  if (2.50 < tension && tension < 2.95)
  {
    if (tension < (pretension - 0.005)) {  // compare them
      elapsedTime =   (micros() - startTime) + 20000;   
      startTime = micros(); 
      digitalWrite(led, HIGH); 
      if(elapsedTime > consigne)
      {
        time = initime;
      }

      delay (time);
      digitalWrite(led, LOW); // do something, they are different
      while (2.50 < tension && tension < 2.95)
      {
        valeur = analogRead (hall);
        tension = valeur * 5.0 / 1024;
        digitalWrite(led, LOW);
      }

    } 
  }

  if (initime == 0)
  { 
    valeur = analogRead (hall);
    tension = valeur * 5.0 / 1024;
    digitalWrite(led, HIGH); 
    delay (20);
    digitalWrite(led, LOW);
  }

  Serial.print("elapsedTime= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(elapsedTime);
  Serial.print("tension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(tension);	
  Serial.print("pretension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(pretension);	
  Serial.print("RPMactuel= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(RPMactuel);	
  Serial.print("intime= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(initime);




  Serial.println();  // Sauter une ligne lors de l'affichage
  Serial.println();
}

if (2.50 < tension && tension < 2.95) and this line is still very very stupid!. Try reading what it says!. ANd thing about this comment

Insert Quote
Quote
and a million microseconds in a second.

Quote
but delayMicroseconds it s not working

how will you know YOU CAN’T SEE IT. Look at the fade example.

Mark

@Holmes

and this line is still very very stupid!.

Maybe if you explained why you think it is very very stupid, jhjh might be able to do something about it.
Or, jhjh might leave it like it is.

if (2.50 < tension && tension < 2.95)

x < y&& x < z

Again and again read it. The OP needs to learn to read his own code.

Mark

No, sorry holmes4, I still don't see your point.
Looks like a perfectly valid range check to me - if voltage is greater than 2.5 and less than 2.95.

It may not be what was intended, but that's no reason to label it stupid, IMO.

Testing a float for equality, OTOH...

The OP needs to learn to read his own code.

Can't argue with that.

AWOL:
No, sorry holmes4, I still don't see your point.
Looks like a perfectly valid range check to me - if voltage is greater than 2.5 and less than 2.95.

It may not be what was intended, but that's no reason to label it stupid, IMO.

Testing a float for equality, OTOH...

The OP needs to learn to read his own code.

Can't argue with that.

thank you AWOL for explaining