Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long average(int newest) {
- #define NUM_SAMPLES 10
- static int data[10];
- static byte index = 0;
- static long sum = 0;
- static byte count = 0;
- sum -= data[index];
- data[index] = newest;
- sum += newest;
- index++;
- index = index % NUM_SAMPLES;
- if (count < NUM_SAMPLES) count++;
- return (float)sum / count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement