function setServoEngaged(index, state)
%SETSERVOENGAGED  Engage (send power to) or disengage a servo motor.
%   setServoEngaged(index, 1) sets the servo motor at the specified 
%   index to engaged (powered).
%
%   setServoEngaged(index, 0) sets the servo motor at the specified 
%   index to disengaged (unpowered).

global ADVSERVO;

if index < 0 || index > 7
    error('index must be in the range 0 to 7');
end
if state ~=0 && state ~= 1
    error('state must be 0 or 1');
end

code = calllib('phidget21', 'CPhidgetAdvancedServo_setEngaged', ADVSERVO, index, state);
if code ~= 0
    error(phidgetError(code));
end
