Wait Command

Does anyone know if there is a 'WAIT' command for the 328????
John

WAIT as in how

there's a couple different delay functions that will stop everything for X time

There's also the millis command that will let you control when things happen. All depends on what you are trying to.

Wait for an event? (Second coming? Rapture?)
Wait until a time has elapsed?

I was thinking of say wait until digital pinX goes high.

Instead of looping around using if, else and goto commands
John

Instead of looping around using if, else and goto commands

Goto? Wash your mouth out!

while (not-the-condition-I'm-waiting-for) 
  {;}

Goto works well if you are in-experienced like me it just takes more code.
I am not as clever as you.
Your while code looks a bit obscure but I will study it in the ref section and see if I can understand it.
Thanks for your help.

I dont suppose you can jump to a sub routine and then return to where you jumped from either. Or am I being stupid?.
John

Please, I beg of you, do not go the way of the Dark Side and use (I can barely bring myself to say it) "goto".

It will bring impossibly large amounts of grief.

Imagine you're waiting for digital pin 1 to go low. You know that pin 1 is currently high.

while (digitalRead (PIN1) == HIGH) {;)
// now we know PIN1 is not high anymore so do what we want to do

There. What could be simpler?

Just had a quick look at the reference section.
So am I understanding it correct

I want to keep checking digital pin 1 and continue with the process when it changes from 0 to 1 and write a 0 to digital pin 2

I guess the script would be something like this

while (digitalpin1 == LOW);
digitalWrite(digitalpin2, LOW);
etc...

Am I close?????
John

Sorry I forgot the digitalRead bit.

I am a little confused by the {:wink:

I think I will have to set up a little test sketch to light an led when I press a switch then I might understand better
john

hay where did that smiley come from.?
I thought I typed { ; )

No, you typed the ; immediately followed by a ). That's an emoticon that the bb software converts to a gif.

Bl???dy clever aint it??
I wish I was

I am a little confused by the { ; }

You could just as well write :

while (condition) ;

Is exactly the same. All it says is "while (condition) "

So, all you do is keep reading the condition until it changes.

OK guy's thanks
I will set up my tester tomorrow and have a play
Thanks for your help, it looks like there is a 'wait' command its just that they call it 'while'

or a simple if, else, g..o sequence..... Sorry I had to say it... ;D ;D ;D

Cheers..... ::slight_smile: ::slight_smile: ::slight_smile:

while loops can be used in different situations other than while x do squat, but if it works for you then go with it

Not at all I asked for a simpler command akin to a wait command and you guy's came thro.
I like the idea of less code.
I am working on changing to WHILE it as we speak.
Regards john
:smiley: :smiley:

OK Guy's,
I knew I would get into trouble.
I am enclosing some code I wrote to read a thermister then map it to a temp range, test it and if it doesn't reach a certain temp them my simple program looped it using goto.
I now want to do the same thing but using WHILE but I can not work out how to make it do a wider loop.
Anyone help me???

Not50c:

                  // read the analog input into a variable:

  int svotempvalue = analogRead(svotemp);     //Read the SVO Thermister

  svotempvalue = map(svotempvalue, 150, 390, 50, 90);


  Serial.print("Oil Temperature ");  
  Serial.print(svotempvalue);
  Serial.println("c"); 

  delay(2000);  


  if (svotempvalue < svotempthreshold)
    goto Not50c;         //if SVO temp lower than 50c then loop until hot



  else

as you see I used a goto loop but now I am trying to be converted.
The svotempthreshold at this point is 50
I sorted the code out for reading a level sensor switch OK (the subject that started this thread)

John
:sunglasses: :sunglasses:

  // Read the temp once
  // read the analog input into a variable:
  int svotempvalue = analogRead(svotemp);     //Read the SVO Thermister
  svotempvalue = map(svotempvalue, 150, 390, 50, 90);

  Serial.print("Oil Temperature ");  
  Serial.print(svotempvalue);
  Serial.println("c");

  delay(2000);  

  // If (while) it's not warm enough, do it again
  while (svotempvalue < svotempthreshold)
  {
     // read the analog input into a variable:
     int svotempvalue = analogRead(svotemp);  //Read the SVO Thermister
     svotempvalue = map(svotempvalue, 150, 390, 50, 90);

     Serial.print("Oil Temperature ");  
     Serial.print(svotempvalue);
     Serial.println("c");

     delay(2000);  
  }

  // Now, it's warm enoug

So what you are saying is that the first sequence sets the initial svotempvalue and it is the sequence between { & } that will keep looping.
I can probably lose the first set of print commands and also the initial delay to reduce the code.

That looks SIMPLES....
Thanks
John
:-* :-*