User Tools

Site Tools


en-us_commands:reference:ianalogreadf

This is an old revision of the document!


IanalogReadf()

IanalogReadf() converts the analog input value to the specified floating-point range.

IanalogReadf command operation flow

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

Commands

Command Arguments Return Value Operation
IanalogReadf(ch, min, max) uint8_t ch — Analog input pin or channel to read
float min — Minimum int32_t conversion result
float max — Maximum int32_t conversion result
float Converts the analog input value to the specified floating-point range.

Example

void setup() {
  Serial.begin(115200);
}
 
void loop() {
  float voltage = IanalogReadf(A0, 0.0F, 10.0F);  // Map the analog input value to the specified floating-point range.
  Serial.println(voltage, 2);
  delay(500);
}

Precautions

  • min and max define the conversion range of the return value, not the actual electrical input range of the sensor.
  • Range limiting by Iscale() or Iscalef() keeps the result between the two specified output endpoints.
  • Setting min greater than max reverses the output range. Example: IanalogRead(A0, 100, 0).
  • MPINO and MPAINO have different raw ADC ranges. Always use ch appropriate to the selected board.
  • Set the MPAINO analog input module's DIP switches and wiring to match the actual input type.
  • This command performs only linear range conversion. Sensor error compensation, open-circuit detection or 4~20mA software Cut requires separate processing.

← Built-in Command List

en-us_commands/reference/ianalogreadf.1788791733.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki