====== IanalogRead() ====== ''IanalogRead()'' converts the analog input value to the specified integer range. {{:en-us_commands:reference:ianalogread.svg?900|IanalogRead command operation flow}} ''int32_t IanalogRead(uint8_t ch, int32_t min, int32_t max)'' ===== Commands ===== ^ Command ^ Arguments ^ Return Value ^ Operation ^ | ''IanalogRead(ch, min, max)'' | ''uint8_t ch'' — Analog input pin or channel to read\\ ''int32_t min'' — Minimum ''int32_t'' conversion result\\ ''int32_t max'' — Maximum ''int32_t'' conversion result | ''int32_t'' | Converts the analog input value to the specified integer range. | ===== Example ===== void setup() { Serial.begin(115200); } void loop() { int32_t percent = IanalogRead(A0, 0, 100); // Map the analog input value to the specified integer range. Serial.println(percent); 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 Commands in the Same Category ===== * [[:en-us_commands:reference:ianalogreadf|IanalogReadf() View detailed description]] [[:en-us_commands:builtin|← Built-in Command List]]