en-us_commands:reference:analogreadavg
This is an old revision of the document!
Table of Contents
analogReadAvg()
analogReadAvg() returns an integer average of multiple input values.
int32_t analogReadAvg(uint8_t ch, uint8_t samples)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
analogReadAvg(ch, samples) | uint8_t chuint8_t samples — Number of averaging samples | int32_t | Returns an integer average of multiple input values. |
Example
void setup() { Serial.begin(115200); } void loop() { int ai0 = analogRead(0); // Read the raw analog value of the specified channel. int ai4 = analogRead(4); // Read the raw analog value of the specified channel. int32_t avg0 = analogReadAvg(0, 5); // Return the integer average of multiple input values. float avg0f = analogReadAvgf(0, 5); // Return the floating-point average of multiple input values. Serial.print("AI0: "); Serial.println(ai0); Serial.print("AI4: "); Serial.println(ai4); Serial.print("AI0 AVG: "); Serial.println(avg0); Serial.print("AI0 AVG float: "); Serial.println(avg0f, 2); delay(500); }
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
A0and MPAINO0do not identify the same physical input. Recheck arguments when changing product families.
en-us_commands/reference/analogreadavg.1788791732.txt.gz · Last modified: by 127.0.0.1
