The following example is a custom function reads from ADC(1) and stores a 3 point moving average.
To prevent large initial error, you must fill up the 3 DM during 1st scan by calling this custom function 3 times.
-------------
The last 3 ADC data are stored in DM[101],DM[102] and DM[103]
' K is the index to keep track of the current ADC data
DM[101+K] = ADC(1) ' data are captured in the DM controlled by K
K = (K+1) mod 3 ' K will vary from 0,1,2
A = (DM[101]+DM[102]+DM[103])/3 ' A is the moving average of last 3
' reading.
A = (A+2)/4*4 ' This line is optional, to eliminate unreal precision
' in the intermediate value due to
' averaging. After this expr the
' result will be in increment of 4 only.
---------------