librpipServoPositionWrite

uint32_t librpipServoPositionWrite(uint32_t id, float angle);

Description

Sets the servo position.

Parameters

  • uint32_t id
    The PWM device to use. The PWM device needs to have been detected during the librpipInit().
  • float angle
    The angle in degrees. 0° is centre. Valid values are -(range/2)° to (range/2)° where range is as per librpipServoConfigWrite()

Returns

0 on failure, 1 on success.

Example

Configure PWM0 for a servo, enable and then alternate between -45° and 45°:

uint32_t feature_set, status;
feature_set = librpipInit(LIBRPIP_BOARD_DETECT, LIBRPIP_FLAG_DEBUG_ON, 0);
if(feature_set & LIBRPIP_FEATURE_PWM0) { 
        librpipServoConfigWrite(0, 120, 1000, 2000);
        librpipPwmStatusWrite(0, LIBRPIP_PWM_STATUS_ON);
        while(1) {
                librpipServoPositionWrite(0, -45.0);
                sleep(5);
                librpipServoPositionWrite(0, 45.0);
                sleep(5);
        }
}
librpipClose();