====== PWM() ====== ''PWM()'' outputs 8-bit or 16-bit PWM on the specified pin. {{:en-us_commands:reference:pwm.svg?900|PWM command operation flow}} ''void PWM(uint8_t pin, uint16_t val, bool onDutybit16 = false)'' ===== Commands ===== ^ Command ^ Arguments ^ Return Value ^ Operation ^ | ''PWM(pin, val, onDutybit16)'' | ''uint8_t pin''\\ ''uint16_t val''\\ ''bool onDutybit16 = false'' | ''void'' | Outputs 8-bit or 16-bit PWM on the specified pin. | ===== Example ===== void setup() { IpidSet(1, 5.0, 0.5, 1.0, 100, 0, 65535); // Set PID coefficients, calculation interval and output range. } void loop() { float pv = ntcReadf(4); // Return the NTC 3950 10kΩ sensor temperature as a floating-point value in °C. float sv = 50.0; uint16_t output = (uint16_t)IpidRun(1, pv, sv); // Calculate the PID output from the current value and setpoint. PWM(12, output, true); // Output 8-bit or 16-bit PWM on the specified pin. } ===== Precautions ===== * Check product-specific PWM pins and timer sharing. * Changing frequency or resolution may also affect other channels on the same timer. * Ensure the connected load is safe when stopping or resetting outputs. ===== Built-in Commands in the Same Category ===== * [[:en-us_commands:reference:fdpwm|FDPWM() View detailed description]] * [[:en-us_commands:reference:pwmoff|PWMOFF() View detailed description]] * [[:en-us_commands:reference:pwm_reset|PWM_RESET() View detailed description]] [[:en-us_commands:builtin|← Built-in Command List]]