Trying to average multiple sensor readings

Hi there,

I'm trying to average out (currently 2 but hopefully more later) sensor readings and then light up the correct led with the average result over pwn.

So essentially its an expanded version of the code found in the example analog -> smooth . is the code i have so far.

When N_SENSORS = 1; it works just how i want it, yet when i try to increase the number of sensors it flashes the led kinda randomly and outputs sometimes huge numbers from sensorTotals..

Kinda lost atm

Any help would be greatly appreciated Thanks.

I think you're storing the results for sensor [1] in sensor [0]'s storage. Your "addValueToDtorage" doesn't put the readings for sensor[1] into "sensorSTORAGE_02".

You could simplify this a lot, and make "sensorStorage" a two-dimensional array.

How i missed that...

Thanks for the two dimensional array pointer. Looks like they could definitely clean things up a bit.

One other thing - you’re using analogue inputs, so “pinMode” isn’t necessary (in fact, it is a bad idea, because it sets the modes for the same-numbered digital pins), and also you’re using PWM outputs, so pinMode isn’t necessary there either.

I was unsure about the pin mode setup, i thought maybe it wasnt necessary but better to include it , so thanks again for your helpful insight..

I was hoping this would be the result of such a post.