Using FOR..NEXT to build a small table
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
Re: Using FOR..NEXT to build a small table
Hi Bob,
You need to create an array to store the readings in, this is untested but here goes:
Code:
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.
Re: Using FOR..NEXT to build a small table
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 ;))
Re: Using FOR..NEXT to build a small table
No it certainly isn't...thanks for spotting that!
Re: Using FOR..NEXT to build a small table
Henrik:
Thanks for the reply although some delayed
Bob