en-us_commands:reference:ianalogwrite
Table of Contents
IanalogWrite()
IanalogWrite() converts a user integer value to the analog output range and outputs it.
void IanalogWrite(uint8_t ch, int32_t min, int32_t max, int32_t value)
Commands
| Command | Arguments | Return Value | Operation |
|---|---|---|---|
IanalogWrite(ch, min, max, value) | uint8_t ch — Analog output pin or channel to writeint32_t min — Minimum of the user input rangeint32_t max — Maximum of the user input rangeint32_t value — User input value to output | void | Converts a user integer value to the analog output range and outputs it. |
Example
const uint8_t DEMAND_INPUT = A0; const uint8_t OUTPUT_CHANNEL = 0; void setup() { Serial.begin(115200); } void loop() { const int32_t demandPercent = IanalogRead(DEMAND_INPUT, 0, 100); // Map the analog input value to the specified integer range. IanalogWrite(OUTPUT_CHANNEL, 0, 100, demandPercent); // Map the user's integer value to the analog output range and output it. Serial.print(F("demand=")); Serial.print(demandPercent); Serial.println(F("%")); delay(250); }
Precautions
- The argument order must be
ch, min, max, value. minandmaxdefine the user input range for interpretingvalue, rather than directly setting the electrical output range.- If
valueis outsidemin~max, the internalIscalef()clamps it to the nearest endpoint. - Setting
mingreater thanmaxreverses the output direction. - If
minequalsmax, the output value is0. - Changing Timer TOP with
analogWriteInit()oranalogWriteFreq()also changes the actualanalogWrite()output range. Use the default TOP65535to retain 16-bit0~65535resolution. - Match the output module DIP switches, external supply and wiring to the connected equipment's input specifications.
- Do not use these together with PWM, pulse output or counter commands using the same timer.
Built-in Commands in the Same Category
en-us_commands/reference/ianalogwrite.txt · Last modified: by 127.0.0.1
