Table of Contents

IanalogRead2()

IanalogRead2() converts the 4~20mA input value to the specified integer range.

IanalogRead2 command operation flow

int32_t IanalogRead2(uint8_t ch, int32_t min, int32_t max)

Commands

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

Example

This example scales the MPINO-8A4R(T)-S 4–20mA input A2 to 0–100%.

void setup() {
  Serial.begin(115200);
}
 
void loop() {
  const int32_t percent = IanalogRead2(A2, 0, 100);  // Scale the A2 4–20mA input to an integer percentage.
  if (percent == ANALOG_READ2_ERROR) {
    Serial.println(F("4-20mA input error"));
  } else {
    Serial.print(F("A2: "));
    Serial.println(percent);
  }
  delay(500);
}

Precautions

Built-in Commands in the Same Category

← Built-in Command List