confused on averages?
moomoo
Posts: 27
I've got the Memsic 2125 input streaming into the microcontroller. I need to take five readings, taking out the high and low number and averaging the other three to get the number to use for my output. I'm storing the five variables in
Temp var word(5), I just don't know how to deal with it after this?
I could If...Then my program to death, but surely there is a better way.
My brain is collapsing, so anybody that can help me would be most appreciated!
By the way, this is for a balance routine if that helps.
·
Temp var word(5), I just don't know how to deal with it after this?
I could If...Then my program to death, but surely there is a better way.
My brain is collapsing, so anybody that can help me would be most appreciated!
By the way, this is for a balance routine if that helps.
·
Comments
Something like this (you will have to complete it).
GOSUB Acceleromter
xsum = x
xMax = x
xMin = x
for counter = 1 to 4
· GOSUB Accelerometer
· xSum = xSum + x
· IF x > xMax THEN xMax = x
· ' More code not shown
If x > xMax then xMax = x
xSum = ABS(xSum - xMax) 'ABS to keep out the negatives
Esleif x < xMin
xSum = ABS(xSum - xMin)
Else
xSum = xSum + x
xTotal = xSum / 3
I was thinking, wouldn't xSum + x be later in the IF...Then statement instead of before, so I could elimate
the Max and Min before adding to Sum. Correct if I'm thinking wrong.