if equal to 0 for 0.5 seconds blink

Is there a code that will do this action

if equal to 0 for 0.5 seconds blink led

I have been searching all the web and I did not find out
thank you everyone

What have you tried?

if (tension == 0);
digitalWrite (led, HIGH);
delay (20);
digitalWrite (led, LOW);

but I did not found the time notion so for example tension = 0 for 50millis blink
you have an idea thx

Here's one possibility. You don't say exactly what you're checking I assumed it would be something like a button (connected to pin 12 in this case); this code means the Arduino is tied up and won't do anything as long as the condition, but you easily could modify it to set a flag and mark the time when the condition is 0, then have a line to check for condition == 1 and check the time elapsed if the flag is set, assuming that it isn't critical to know exactly how long the condition was 0 since some time may elapse before the routine gets around to checking.

You can also use an interrupt pin if the timing is critical

void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, INPUT);
  digitalWrite(12, HIGH); // turn on pullup resistor so pin stays HIGH
}

void loop(){
  if(digitalRead(12) == LOW){
    long startTime = millis();
    while(digitalRead(12) == LOW);
    if ((millis() - startTime) > 500){
      blink();
    }
  }
}

void blink(){
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
}
int bobine = 13; // Alimentation de la bobine
int capteur = A0; // Analyse du capteur a effet capteur
long startTime  = 0;                    // start time for stop watch
long elapsedTime = 0 ;



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

void setup() // Effectuer une seule fois
{
  pinMode (capteur, INPUT); // Declarer capteur a effet capteur comme INPUT
  pinMode (bobine, OUTPUT); // Declarer bobine comme OUTPUT
  Serial.begin (38400); // Vitesse du retour des donnees
}


void loop() // Effectuer à chaque fois
{
  pretension = tension; // Tension precedente vs tension actuelle
  valeur = analogRead (capteur); // Lecture du capteur a effet capteur
  tension = valeur * 5.0 / 1024; // Formule de calcul du voltage du capteur a effet capteur

if ( tension == pretension)
{digitalWrite(bobine, HIGH); 
      delay (50);
      digitalWrite(bobine, LOW);
    delay (300);}

  if (tension > 2.51 && tension < (pretension - 0.005))
  {   elapsedTime =   micros() - startTime;   
      startTime = micros(); 
      digitalWrite(bobine, HIGH); 
      delay (20);
      digitalWrite(bobine, LOW); // do something, they are different
      while (tension > 2.51){
        pretension = tension;
        valeur = analogRead (capteur);
        tension = valeur * 5.0 / 1024;
        digitalWrite(bobine, LOW);
      

    } 
  }



  Serial.print("tension= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(tension);	
  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("valeur= ");  // Imprimer les valeurs pecedentes du capteur 
  Serial.println(valeur);

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

here is all my code but this the particular part;

if ( tension == pretension)
{digitalWrite(bobine, HIGH); 
      delay (50);
      digitalWrite(bobine, LOW);
    delay (300);}

I am trying to add a time so for example it stay s equal for 0.5 seconds do…

Not sure I understand exactly what you want - do you want to blink the light if Tension == pretension for at least 0.5 seconds?

yes exactly

Sleepydoc:
Not sure I understand exactly what you want - do you want to blink the light if Tension == pretension for at least 0.5 seconds?

I have a similar scenario but it deals with an analog ready from pin A0.

I want to say that if a SensorValue drops below 224.5 for more than 0.5 secs then set one of the digital pins to high.

if (SensorValue < 924.5)
      {  
        digitalWrite(LC, HIGH);
delay(300);
}

how is something like that expressed?

yeah thats it but how to write it I dont see this condition
if he is equal for more than 0.5 secs then set one of the digital pins to high.
please explain thx

crullier:
I hope someone can help you (us) because my goggling is not yielding results..

please explain thx

how is something like that expressed?

Did you guys actually read Sleepydoc's post where the solution is given, Reply #3? Not a perfect solution by Sleepydoc's own admission, since it essentially blocks for half a second, but hey it 'll work and gives the basis for improvement.

Jhjh:
Is there a code that will do this action

if equal to 0 for 0.5 seconds blink led

I have been searching all the web and I did not find out
thank you everyone

Yes, there is "a code" that will do what you want. It will be "a code" that you write yourself. You repeatedly ask for people to write code for you when you can't find the exact code that will do some arbitrary thing you want to do. Do some research. Learn from the code you do find that handles each part of what you want to do.

You want to detect a button press. Detect it! There are plenty of examples. You want to know how long some condition exists. So time it! You want to blink a LED. So blink it! Every single one of these this is included in the example code that comes with the Arduino IDE. Do a little of your own research and learn how simple things are done. Build on the things you know, one thing at a time.

For your particular question in this thread (only one of the many threads begging for folks to write your code), read and understand the example called Blink Without Delay. If you don't understand it, study it again. Play with it. Change it. See what the changes do. Then incorporate the techniques in your own program.

Just stop asking people to write your programs for you. This is not a code writing service. There are plenty of people here who are willing to help anyone who actually tries to help themselves, but many of those, including me, have little or no patience with those who won't even try.

  if (tension > 2.51 && tension < (pretension - 0.005))

So you fixed it! What happened to over other threads asking the same questions about the same code?

Mark

lar3ry:

Jhjh:
Is there a code that will do this action

if equal to 0 for 0.5 seconds blink led

I have been searching all the web and I did not find out
thank you everyone

Yes, there is “a code” that will do what you want. It will be “a code” that you write yourself. You repeatedly ask for people to write code for you when you can’t find the exact code that will do some arbitrary thing you want to do. Do some research. Learn from the code you do find that handles each part of what you want to do.

You want to detect a button press. Detect it! There are plenty of examples. You want to know how long some condition exists. So time it! You want to blink a LED. So blink it! Every single one of these this is included in the example code that comes with the Arduino IDE. Do a little of your own research and learn how simple things are done. Build on the things you know, one thing at a time.

For your particular question in this thread (only one of the many threads begging for folks to write your code), read and understand the example called Blink Without Delay. If you don’t understand it, study it again. Play with it. Change it. See what the changes do. Then incorporate the techniques in your own program.

Just stop asking people to write your programs for you. This is not a code writing service. There are plenty of people here who are willing to help anyone who actually tries to help themselves, but many of those, including me, have little or no patience with those who won’t even try.

shut up if you don’t know how to answer their is an exit button on the right side of your screen click on it and get away of arduino forum if you are not able to answer but if you are able answer TO THE QUESTION ONLY don’t write a novel. I dont care what you think about MY life or my way to work if am trying LEAVE me if you don’t want to help because I dont give a shit about what you say.

holmes4:

  if (tension > 2.51 && tension < (pretension - 0.005))

So you fixed it! What happened to over other threads asking the same questions about the same code?

Mark

and are you able to see your last posts you was only giving STUPID COMMENTS stop and live you life and leave others live their life.

Jhjh:
shut up if you don't know how to answer their is an exit button on the right side of your screen click on it and get away of arduino forum if you are not able to answer but if you are able answer TO THE QUESTION ONLY don't write a novel. I dont care what you think about MY life or my way to work if am trying LEAVE me if you don't want to help because I dont give a shit about what you say.

Oh, I KNOW the answers to all the questions you've asked, but I choose not to tell you, for all the reasons I gave you. I will be ignoring you from now on, because you are not worth helping.

[/quote]

Oh, I KNOW the answers to all the questions you've asked, but I choose not to tell you, for all the reasons I gave you. I will be ignoring you from now on, because you are not worth helping.

[/quote]
I don't give a shit about your answers first if you want to give them give them but I think your old enough to be mature and stop acting like babies.

I KNOW the answers to all the questions I choose not to tell you

I simply don't know the reasons you know why ?because I don't like the author of the novel who is you!!!! sorry I did not payed attention for sentences that you wrote!!! don't cry plz! dear baby.

@OP: Apparently, you haven't read Norman Vincent Peale's "How to Win Friends and Influence People".

It is quite clear that you are in over your head and simply floundering about asking a million questions instead of trying to think. I suspect that English is not your native language, and that may be contributing to your difficulties expressing yourself. However, it is clear that you are taking a class, and your FIRST avenue for help is supposed to be your teacher. Ask him/her, first. Clearly, you need one-on-one help (or maybe professional help). That needs to come from your teacher, not us.

lar3ry++
PaulS++

Pete

This thread is now locked and has earned user Jhjh a three day ban on posting.

Personally, I'm bored with repeating myself warning and merging the cross-posts of this user, so I'm hoping Jhjh will use the time-out as useful learning and reflection time.
Any future repetition will result in an extension of the ban.

Creation, use or resurrection of sock-puppets will result in a total ban.

Edit: within 40 seconds of discovering the ban on Jhjh, user/sock puppet john191498 also discovered a ban.
Amazing coincidence, or what?
A bit like the coincidence that two different users should have the same confusion between the ' (apostrophe) key and the > key.
Weird.