View previous topic :: View next topic |
Author |
Message |
jfk1965
Joined: 21 Oct 2003 Posts: 58
|
Best way to sort?? |
Posted: Wed Apr 05, 2006 4:56 am |
|
|
Help minds gone blank just can't think this one through at the moment.
I have an array with 10 readings from the 10 ADC pins stored in it, I need to find which one is the lowest value what's the easiest way to do this without endless if statements.
thanks
JFK |
|
|
sjbaxter
Joined: 26 Jan 2006 Posts: 141 Location: Cheshire, UK
|
|
Posted: Wed Apr 05, 2006 5:18 am |
|
|
Try this ...
Code: | int8 lowestValueIndex;
uint16 lowestValue;
lowestValue = 0xFFFF; // max value for a uint16
lowestValueIndex = -1;
for (i=0; i<10; i++) {
if (myValues[i] < lowestValue) {
lowestValue = myValues[i];
lowestValueIndex = i;
}
}
|
lowestValue should use the same variable type as myValues[].
Although you should have been able to figure this one out !!! _________________ Regards,
Simon. |
|
|
Ttelmah Guest
|
|
Posted: Wed Apr 05, 2006 5:19 am |
|
|
Depends how old your compiler is, but if it is recent, look at 'Qsort' in the manual.
Best Wishes |
|
|
jfk1965
Joined: 21 Oct 2003 Posts: 58
|
|
Posted: Wed Apr 05, 2006 7:40 am |
|
|
Thanks guys, I now I should have been able to do this but we have builders in our building at the moment and they are cutting a wall with a cutting disk so it's a little difficult to concentrate.
JFK |
|
|
|