Shop OBEX P1 Docs P2 Docs Learn Events
Comparing values in an array... — Parallax Forums

Comparing values in an array...

Matt WhiteMatt White Posts: 60
edited 2006-07-17 13:19 in General Discussion
I'm using an ADC0834 to process analog·readings from 4 Sharp GP2D12 sensors.· All that works fine.· I have an array called adc(0,1,2, ...).· Essentially what I want to do is evaluate the four sensor readings stored in the array and find out which one has the largest value.· While this seems like an easy task when I start coding it, the excersize turns into a lots and lots of IF, THEN, ELSE statements... Anyone got a better way to do this?·

Would I be better off just checking each value against a set of threasholds?· The application is colision avoidance -- I'd also like to know "how far" I am from an object, wall, etc.· The idea being the closer I am to an obstacle the more of a course correction I need to make.

Thanks!
Matt
·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-17 04:43
    Are the values all evaluated the same way? How about a FOR loop?
    lastFound = 0
    highest = adc(0)
    for i = 1 to 7
      if adc(i) < highest then skipIt
      highest = adc(i)
      lastFound = i
    skipIt:
    next
    
    


    The testing in the loop can be more complex as long as all items are treated alike.
  • Matt WhiteMatt White Posts: 60
    edited 2006-07-17 13:19
    Perfect. Thanks Mike!
Sign In or Register to comment.