Log in

View Full Version : Using FOR..NEXT to build a small table



bob425
- 16th August 2011, 19:39
I'm looking for a code efficient method to build a small table during runtime.

Although I’ve looked at mel PIC BASIC Pro, FAQ, Code Examples and PBP Extensions I haven’t found an answer; albeit, I may have overlooked an answer.

Here is the code example I’ve started even though it doesn’t compile.

‘--------------------------------------------------------------------------------------------------
highpres1 var byte
highpres2 var byte
highpres3 var byte

highpresn var byte
‘------------------------------------------------------------------------------------------------------
if pres > 1700 then ‘voltage from pressure transducer
high hiled ‘led on to verify that pressure > 1700
for i = 1 to n step 1
adcin 4, highpresi ‘the ‘i’ at the end of highpres (i) is intended to
‘identify ‘successive variables
next i
else
endif
‘-------------------------------------------------------------------------------------------------------

Question: How can ‘i’ be used to identify successive variables without extensive code?
Thanks,
Bob

HenrikOlsson
- 16th August 2011, 20:29
Hi Bob,
You need to create an array to store the readings in, this is untested but here goes:

n CON 5 ' Number of sample
Readings VAR [n] ' Create array of size n
i VAR BYTE

' Get values
For i = 0 to (n-1) ' Take n readings
ADCIN 0, Readings[i]
Pause 10
NEXT

' Display values
For i = 0 to (n-1)
HSEROUT ["Reading ", #i, ": ", #Readings[i],13
Next


/Henrik.

cncmachineguy
- 16th August 2011, 21:34
Can't get my dumb phone to select for quote, but you will need a closing bracket in the hserout line after the 13. 13]
(not henriks day for brackets ;))

HenrikOlsson
- 17th August 2011, 07:04
No it certainly isn't...thanks for spotting that!

bob425
- 8th January 2012, 02:23
Henrik:

Thanks for the reply although some delayed

Bob