high/low of 14 numbers


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425

    Default high/low of 14 numbers

    I referenced this thread: http://www.picbasic.co.uk/forum/showthread.php?p=41702

    I can't figure out how to get started. I can do it with a 2 or 3 numbers but then the code gets too large and I lose track. What I need to do is it take in 14 byte sized numbers. Then I need to average them, which I've done, but then I need to find the high and low numbers. The numbers a whole numbers and range from 18-25.

    Can someone help me get started?

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


    Did you find this post helpful? Yes | No

    Default Re: high/low of 14 numbers

    Hi,
    If all you need to do is "peak detect" (and not actually sort the values) then something like this might work
    Code:
    Values VAR BYTE[14]  ' Array to store the 14 values, array is indexed 0-13.
    HighValue VAR BYTE   ' Highes value found
    LowValue VAR BYTE    ' Lowest value found
    i VAR BYTE
    Temp VAR BYTE
    
    HighValue = 0
    LowValue = 255
    
    For i = 0 to 13
      Temp = Values[i]
      IF Temp > HighValue THEN  HighValue = Temp ' Found new high value
      IF Temp < LowValue THEN  LowValue = Temp  ' Found new low value
    NEXT
    
    LCDOUT $FE, 1 , "Low: ", #LowValue, "  High: ", #HighValue
    You can skip using the Temp variable and index the array directly if you want but it'll produce slightly larger code.

    /Henrik.

  3. #3
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: high/low of 14 numbers

    Thanks for the help Henrik. I don't understand your code so I have some questions/comments:

    1. I am still using 2.50. Is the top line (Values VAR BYTE[14]) wanting to use arraywrite? I'm assuming your code, if written out, would be Values.1, Values.2......

    2. I already store the 14 byte sized variables into D1, D2, D3....D14. Could this be a direct substitution?

    3. Your code states "Values[i]." The "i" would be 14 in this case?

    4. Last question. When you put a # before the lowvalue and highvalue, what exactly is that doing?
    Last edited by Christopher4187; - 15th December 2012 at 12:57.

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


    Did you find this post helpful? Yes | No

    Default Re: high/low of 14 numbers

    Hi,
    1. I am still using 2.50. Is the top line (Values VAR BYTE[14]) wanting to use arraywrite? I'm assuming your code, if written out, would be Values.1, Values.2......
    No, it does declare an array but it does not use ARRAYWRTITE or ARRAYREAD so you should be fine. The individual values in the array are accessed like Values[0], Values[1] and so on.

    2. I already store the 14 byte sized variables into D1, D2, D3....D14. Could this be a direct substitution?
    Not directly, no. But if you don't want to re-write your code you can create aliases for each of your variables to actually use the declared array
    Code:
    Values VAR BYTE[14]
    D1 VAR Values[0]
    D2 VAR Values[1]
    D3 VAR Values[2]
    '...and so on.
    This way, when you assign a value to D3 it'll actually be stored in the array.

    3. Your code states "Values[i]." The "i" would be 14 in this case?
    No, i is a variable which is used as the index in the FOR-NEXT loop. First time thru the loop i is 0 so it will access the first value in the array, next time thru the loop i is 1 so it will access the second value in the array and so on. Remember that arrays are indexed starting at 0 so Value[0] is the first value, Value[13] is the 14th value.

    4. Last question. When you put a # before the lowvalue and highvalue, what exactly is that doing?
    It converts the value to readable ASCII text, it's the same as using the DEC modifier.

    /Henrik.

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default Re: high/low of 14 numbers

    Thanks for the help Henrik! It works very well! One question - Is there an advantage to using # instead of DEC?

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: high/low of 14 numbers

    No, not that I know of. With DEC you can specify the number of digits, like DEC3 or print signed numbers with SDEC but as far as I know # is the same as DEC.

    /Henrik.

Similar Threads

  1. LCD Low Power
    By kduck63 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th December 2012, 00:05
  2. PCB low volume production
    By sales5 in forum Adverts
    Replies: 0
    Last Post: - 29th November 2012, 03:43
  3. Problem with Tracy Allen digital low pass filter?
    By DSaum in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th November 2012, 19:22
  4. Replies: 3
    Last Post: - 25th November 2012, 20:26
  5. high voltage high frequency H-Bridge
    By George in forum Off Topic
    Replies: 6
    Last Post: - 27th April 2009, 11:50

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