AS2 Average
From RISDpedia
var sampleLenght = 10 //number of samples you want to use sample.push(_nada.arduinosms1.analogin0); // add newest value to the sample pool var n:Number = 0; // reset the total for (i = 0; i < sample.length; i++) { // add the pool of samples n += sample[i]; } var avg = n / sample.length; //average the samples (divide the total by the length) _root.avg.text = Math.round(avg); // display the current sample average if(sample.length > sampleLenght){ // remove oldest sample to make room for the newest one sample.shift(); }
NOTE: All information contained within this article is pure opinion. Although this article is intended to help students, it may contain faulty or misleading information. This article is not to be considered professional opinion or advice, and is in no way a replacement for reading all safety/instructional documentation. Always remember to protect yourself when handling/using hazardous materials, as well as test new techniques before using them on projects/work intended to be handed in or used.
RISDpedia and its contributers take NO responsibility for the information contained within.
RISDpedia is not an official site of the Rhode Island School of Design.

