Table of Contents

IanalogRead2f()

IanalogRead2f() converts the 4~20mA input value to the specified floating-point range.

IanalogRead2f command operation flow

float IanalogRead2f(uint8_t ch, float min, float max)

Commands

Command Arguments Return Value Operation
IanalogRead2f(ch, min, max) uint8_t ch — MPINO: analog pin such as A0; MPAINO: overall module channel number starting at 0
float min
float max
float Converts the 4~20mA input value to the specified floating-point range.

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 = IanalogRead2f(0, 4.0F, 20.0F);  // Scale the CH0 4–20mA input to milliamps.
  if (value == (float)ANALOG_READ2_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