User Tools

Site Tools


en-us_commands:analog_input

This is an old revision of the document!


Analog Input and Range Conversion

Command Return Value / Purpose
Iscale(x, inMin, inMax, outMin, outMax) Converts the integer input range to the desired integer range.
Iscalef(x, inMin, inMax, outMin, outMax) Converts to a floating-point range while retaining fractional values.
analogReadInit(sps) Sets the sampling rate of the analog input module.
analogRead(ch) Reads the raw analog value.
analogReadAvg(ch, samples), analogReadAvgf(…) Returns integer or floating-point averages.
IanalogFilter(id, raw, samples) Applies a moving average to the supplied value.
IanalogRead(ch, min, max), IanalogReadf(…) Converts the measurement to the user range.
analogRead2(ch), analogRead2Avg(ch, samples) Reads the corrected 4~20mA input.
IanalogRead2(ch, min, max), IanalogRead2f(…) Converts the 4~20mA value to the user range.
void setup() { analogReadInit(IANALOG_SPS_64); }
void loop() {
  float value = IanalogReadf(0, 0.0, 100.0);
}

Command Prototypes

Return Type Command Prototype
int32_t Iscale(int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max)
float Iscalef(float x, float in_min, float in_max, float out_min, float out_max)
void analogReadInit(uint16_t sps)
int analogRead(uint8_t pin)
int32_t analogReadAvg(uint8_t ch, uint8_t samples)
float analogReadAvgf(uint8_t ch, uint8_t samples)
int32_t IanalogFilter(uint8_t id, int32_t raw_value, uint8_t samples)
int32_t IanalogRead(uint8_t ch, int32_t min, int32_t max)
float IanalogReadf(uint8_t ch, float min, float max)
uint16_t analogRead2(uint8_t ch)
int32_t analogRead2Avg(uint8_t ch, uint8_t samples)
float analogRead2Avgf(uint8_t ch, uint8_t samples)
int32_t IanalogRead2(uint8_t ch, int32_t min, int32_t max)
float IanalogRead2f(uint8_t ch, float min, float max)

First check the channel, input module voltage/current selection and DIP switch settings. Increasing the averaging count stabilizes values but slows response.

← Built-in Command List

en-us_commands/analog_input.1788785564.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki