Using FOR..NEXT to build a small table


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2006
    Posts
    8

    Question 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

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default 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.

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

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

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Using FOR..NEXT to build a small table

    No it certainly isn't...thanks for spotting that!

  5. #5
    Join Date
    May 2006
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: Using FOR..NEXT to build a small table

    Henrik:

    Thanks for the reply although some delayed

    Bob

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts