output_pwm()

Sets the PWM (Pulse Width Modulation) output on a specified pin.

Syntax

planetcnc.output_pwm(pin, duty, frequency=None)

Parameters

Parameter Type Description Comment
pin int The output pin number.
duty float Duty cycle (0.0 - 100.0).
frequency float PWM frequency in Hz. If omitted, the frequency is default. optional

Return Value

Examples

#! /usr/bin/env python
 
import planetcnc
 
# Set PWM output on pin 1 with 50% duty cycle and 1000 Hz frequency
if planetcnc.output_pwm(1, 50.0, 1000.0):
    print("PWM output set successfully.")
else:
    print("Failed to set PWM output.")
 
# Set PWM output on pin 6 with 75% duty cycle, keeping current frequency
if planetcnc.output_pwm(6, 75.0):
    print("PWM duty cycle updated successfully.")
else:
    print("Failed to update PWM duty cycle.")

See also

estop
stop
pause
start
output
output_pwm
output_rc
open
close