All pastes #2689643 Raw Edit

Something

public unlisted text v1 · immutable
#2689643 ·published 2014-03-31 19:02 UTC
rendered paste body
component movavg "Rolling average";
pin in float in "value in";  
pin out float out "moving average out";
pin in unsigned PTA "number of points to average over - max 20";


variable float old;
variable int avgindex = 0;
variable float avgarray[20];

function _;
license "GPL"; // indicates GPL v2 or later
;;
int avgloop=0;
float avgadd = 0;
avgarray[avgindex]=in;

//add stuff and divide by PTA

for (avgloop = 0 ; avgloop < PTA ; avgloop++)
	{
		avgadd=avgadd+avgarray[avgloop];
	}

avgindex = ( avgindex + 1 ) % PTA;

out = avgadd/PTA;