PWM

Not all the XBee protocols support pulse-width modulation (PWM) output handling, but the XBee Java Library provides functionality to manage them. When you configure an IO line as PWM output, you must use specific methods to set and read the duty cycle of the PWM.

For the set case, use the method setPWMDutyCycle(IOLine, double) and provide the IO line configured as PWM and the value of the duty cycle in % of the PWM. The duty cycle is the proportion of 'ON' time to the regular interval or 'period' of time. A high duty cycle corresponds to high power, because the power is ON for most of the time. The percentage parameter of the set duty cycle method is a double, which allows you to be more precise in the configuration.

Setting the duty cycle of an IO line configure as PWM
[...]

// Set a duty cycle of 75% to the DIO10_PWM0 line (PWM output).
myXBeeDevice.setPWMDutyCycle(IOLine.DIO10_PWM0, 75);

[...]

The setPWMDutyCycle() method may fail for the following reasons:

The getPWMDutyCycle(IOLine) method of a PWM line returns a double value with the current duty cycle percentage of the PWM.

Getting the duty cycle of an IO line configured as PWM
[...]

// Get the duty cycle of the DIO10_PWM0 line (PWM output).
double dutyCycle = myXBeeDevice.getPWMDutyCycle(IOLine.DIO10_PWM0);

[...]

The getPWMDutyCycle() method may fail for the following reasons:

Note In both cases (get and set), the IO line provided must be PWM capable and must be configured as PWM output.