REM This code will apply a low pass filter to an analog input reading  - @AN
REM The amount of filtering is determined by the variable 'i' 
REM    greater the value of i, more filtering is performed
REM The #DISP loop will show the result 'res' and the summed value 'ttl'
REM variables
REM res = result or filtered analog reading
REM ttl = sum of analog readings
REM a[] = array of analog readings
REM i = # of analog reads/puesdo time constant
REM j = i-1
REM n = counter to step through array a[]

REM Main program
i= 1000
j= i-1
ttl= @AN[1]*j
res= @AN[1]
DA *[]
DM a[i]
n= 0

REM Initialize array with analog reads
a[n]= @AN[1]
n= n+1
JP #init,n<i

REM Run #DISP in thread 1 - will display variables 'res' and 'ttl'
XQ #disp,1

REM #A is the filter.  It takes the most recent reading, tosses out the oldest
REM       reading, sums the values and takes an average.
n= 0
a[n]= @AN[1];          'Current value
ttl= ttl-a[n+1]+a[n];  'sum in current value and subract oldest value
n= n+1
res= ttl/j;            'filtered reading

REM if last read then subtract first array element and reset 'n'
JP #a,n<j
a[n]= @AN[1]
ttl= ttl-a[0]+a[n]
res= ttl/j
n= 0
JP #a

REM display 'res' and 'ttl' every 100ms
WT 100
MG res, ttl
JP #disp