Go Down

Topic: Wait Command (Read 3825 times) previous topic - next topic

Osgeld

while loops can be used in different situations other than while x do squat, but if it works for you then go with it
http://arduino.cc/forum/index.php?action=unread;boards=2,3,4,5,67,6,7,8,9,10,11,66,12,13,15,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,86,87,89,1;ALL

John Siddle

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
:D :D

John Siddle

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: [Select]

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

PaulS

Code: [Select]
 // 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



John Siddle

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

AWOL

Code: [Select]
// 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.
"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.

John Siddle

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: [Select]


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

Go Up