Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. long average(int newest) {
  2. #define NUM_SAMPLES 10
  3. static int data[10];
  4. static byte index = 0;
  5. static long sum = 0;
  6. static byte count = 0;
  7.  
  8. sum -= data[index];
  9. data[index] = newest;
  10. sum += newest;
  11. index++;
  12. index = index % NUM_SAMPLES;
  13. if (count < NUM_SAMPLES) count++;
  14.  
  15. return (float)sum / count;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement