REM Example program that creates a function called by JS that fills array with analog
REM  reads and returns the average

n= 10;'number of array elements
DM array[n];'dimension array

'Read and average 10 analog values on AN1
JS #getan(1,"array",n)
avg= _JS;'capture the returned analog average
EN

REM #getAN(analog input, array name, # of elements)  returns average of analog reads
REM ^a = analog input (passed from JS call)
REM ^b = array name (passed from JS call)
REM ^c = number of array elements (passed from JS call)
REM ^d = counter
REM ^e = sum of array elements 
#getan
^d= 0;^e= 0;'initialize counter and sum
#read
^b[^d]= @AN[^a];'read analog values into array
^e= ^e+^b[^d];'add current array element to sum
^d= ^d+1;'increment counter
JP #read,(^d<^c);'repeat until array is full
EN ,,(^e/^c);'return average in _JS