Pages: 1 [2]   Go Down
Author Topic: Wait Command  (Read 3451 times)
0 Members and 1 Guest are viewing this topic.
SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Alsager, Stoke on Trent
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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-grin smiley-grin
Logged

Alsager, Stoke on Trent
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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???

Code:
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
 8-) 8-)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50452
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
 // 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

Logged

Alsager, Stoke on Trent
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
 :-* :-*
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 309
Posts: 26525
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
// 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);
  }


Really, what you want here is a "do { } while();" loop, not a "while" loop.
A "do..while" will always execute the loop code at least once, whereas a "while" loop may skip it completely.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Alsager, Stoke on Trent
Offline Offline
Newbie
*
Karma: 0
Posts: 46
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi AWOL
Just looked up the do...while command.
Is this what you mean.....  Perhaps I dont need the first read/print sequence at all......

Code:

  // Check the oil temp is 50c

do
{
  
     // 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);
  }

while (svotempvalue < svotempthreshold);

//Oil is 50c. So go to next sequence



John
 :-? :-?
Logged

Pages: 1 [2]   Go Up
Jump to: