librpipPwmDutyPercentWrite
uiuint32_t librpipPwmDutyPercentWrite(uint32_t id, float duty_cycle);
Description
Sets the PWM duty cycle as a percentage of the current period. An alternative to using librpipPwmConfigWrite.
Parameters
- uint32_t id
The PWM device to read. The PWM device needs to have been detected during the librpipInit(). - float duty_cycle
The duty cycle as a percentage of the period instead of nano seconds. Valid values are anything between 0.0 (fully off) and 100.0 (fully on).
Returns
0 on failure, 1 on success.
Example
Configure, enable and then alternate between 25% and 75% duty cycles:
uint32_t feature_set, status; feature_set = librpipInit(LIBRPIP_BOARD_DETECT, LIBRPIP_FLAG_DEBUG_ON, 0); if(feature_set & LIBRPIP_FEATURE_PWM0) { librpipPwmConfigWrite(0, 10000, 10000, LIBRPIP_PWM_FLAG_POLARITY_NORMAL); librpipPwmStatusWrite(0, LIBRPIP_PWM_STATUS_ON); while(1) { librpipPwmDutyPercentWrite(0, 25.0); sleep(5); librpipPwmDutyPercentWrite(0, 75.0); sleep(5); } } librpipClose();