SE USA
Offline
Faraday Member
Karma: 33
Posts: 3619
@ssh0le
|
 |
« Reply #15 on: December 11, 2009, 06:46:25 pm » |
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
|
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
|
|
|
|
Alsager, Stoke on Trent
Offline
Newbie
Karma: 0
Posts: 46
Arduino rocks
|
 |
« Reply #16 on: December 12, 2009, 02:10:53 pm » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Alsager, Stoke on Trent
Offline
Newbie
Karma: 0
Posts: 46
Arduino rocks
|
 |
« Reply #17 on: December 12, 2009, 02:38:44 pm » |
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 8-) 8-)
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 311
Posts: 35473
Seattle, WA USA
|
 |
« Reply #18 on: December 12, 2009, 02:47:57 pm » |
// 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
Newbie
Karma: 0
Posts: 46
Arduino rocks
|
 |
« Reply #19 on: December 12, 2009, 03:07:58 pm » |
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
Online
Brattain Member
Karma: 137
Posts: 19017
I don't think you connected the grounds, Dave.
|
 |
« Reply #20 on: December 12, 2009, 05:07:11 pm » |
// 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.
|
|
|
|
Alsager, Stoke on Trent
Offline
Newbie
Karma: 0
Posts: 46
Arduino rocks
|
 |
« Reply #21 on: December 12, 2009, 08:24:03 pm » |
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...... // 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
|
|
|
|
|
|