Table of Contents

analogRead2Avgf()

analogRead2Avgf() returns a floating-point average of 4~20mA input values.

analogRead2Avgf command operation flow

float analogRead2Avgf(uint8_t ch, uint8_t samples)

Commands

Command Arguments Return Value Operation
analogRead2Avgf(ch, samples) uint8_t ch — MPINO: analog pin such as A0; MPAINO: overall module channel number starting at 0
uint8_t samples — Number of moving-average read samples; up to 20
float Returns a floating-point average of 4~20mA input values.

Example

Connect an X input module to MPAINO-8A8R(T) and select Analog Input Module → X. Set CH0 DIP switches 20mA and GND to ON, then connect the 4–20mA signal.

void setup() {
  Serial.begin(115200);
}
 
void loop() {
  const float value = analogRead2Avgf(0, 5);  // Read the floating-point moving average of up to five recent valid values.
  if (value == (float)ANALOG_READ2_AVG_ERROR) {
    Serial.println(F("4-20mA input error"));
  } else {
    Serial.println(value, 2);
  }
  delay(500);
}

Precautions

Built-in Commands in the Same Category

← Built-in Command List