====== IanalogFilter() ====== ''IanalogFilter()'' applies a moving average to the supplied value. {{:en-us_commands:reference:ianalogfilter.svg?900|IanalogFilter command operation flow}} ''int32_t IanalogFilter(uint8_t id, int32_t raw_value, uint8_t samples)'' ===== Commands ===== ^ Command ^ Arguments ^ Return Value ^ Operation ^ | ''IanalogFilter(id, raw_value, samples)'' | ''uint8_t id'' — Filter ID\\ ''int32_t raw_value'' — New input value\\ ''uint8_t samples'' — Number of averaging samples | ''int32_t'' | Applies a moving average to the supplied value. | ===== Example ===== void setup() { Serial.begin(115200); analogReadInit(IANALOG_SPS_128); // Set the analog input module's sampling rate. } void loop() { const int32_t raw = analogRead(A0); // Read the raw analog value of the specified channel. const int32_t filtered = IanalogFilter(0, raw, 10); // Process the supplied value using a moving average. static int32_t previous = 0; if (abs(filtered - previous) >= 5) { previous = filtered; Serial.println(filtered); } } ===== Precautions ===== * First check the supported channels and module DIP switch input ranges for the product. * Do not use error constants as normal measurements. * Increasing the sample count slows response and increases memory usage. * MPINO ''A0'' and MPAINO ''0'' do not identify the same physical input. Recheck arguments when changing product families. [[:en-us_commands:builtin|← Built-in Command List]]