PDA

View Full Version : Help with loop



wildbilly
- 1st January 2007, 17:18
Greetings to all for 2007. Let's hope we will be wiser this year. All members have been very helpfull. I am have great difficulty figuring out how to get this done. I have included some of the code below. The code reads the adc value and stores it. Then it checks to see if the value is in range. When it is the code carrys on to the next command which checks and now that it is in range for the first time it starts counting to 30 before going to the main label to turn on port pins and display on the LCD. Here is where I am stuck. While the counting is running, if the real value at Pin 0 (adval pin) changes and goes out of range. I want at the end of the count for the program to check if the value is still in range before carrying to main label. Remember, this is what caused it to start counting, being in range. If it is out of range go back to loop. The problem is that the code cannot do this because it is counting and even though pin 0 has changed adcin does not have chance to read Pin 0.
I hope I have explained this clearly. If not I will try again. Thanks to all.

loop:

adcin 0, adval ' Read adc value and store in adval
if adval <= 668 or adval >= 839 then ' if adval is out of range
restore = 0 ' clear restore
LCDout $FE,2," Water Level = ",DEC Level ' Display Level
lcdout " Out of Range " ' Display out of range
goto loop
ENDIF

if adval > 668 OR adval < 839 then ' If adval is in range
restore = restore + 1 ' Increment restore timer var
if restore = 1 then ' If restore is equal to 1 then
goto Wait_timer ' Go to Wait_timer
else ' else
goto main ' go to main label
Wait_timer: ' Wait label

for i = 1 to 30 ' Count to 30
lcdout $fe,2
lcdout " "
lcdout $FE, $C0 ' Move cursor to second line
lcdout " Waiting to Restore" ' Display Waiting to Restore
lcdout $FE, $94 ' Move cursor to third line
lcdout " Level " ' Display Level
lcdout $FE, $D4 ' Move cursor to fourth line
lcdout " ", dec i ' Display Count value
Next i ' next count value

endif
endif

main:

IF adval >= 737 AND adval <= 770 THEN ' Check if adval is in a range
leds = 17
LCDout $FE,2," Water Level = ",DEC Level,
endif

paul borgmeier
- 2nd January 2007, 04:32
Why not duplicate the ADCIN and IF-THEN in your count to 30 loop, thus checking each time through the count loop?

wildbilly
- 2nd January 2007, 16:59
Thanks Paul. I had a good laugh when I read you response. I would have responded the same way you did. I went dud! What was I thinking? Sometimes I think I make things much too difficult than it really is.

Thanks..