Function controller_get_analog

Source
pub unsafe extern "C" fn controller_get_analog(
    id: controller_id_e_t,
    channel: controller_analog_e_t,
) -> i32
Expand description

Gets the value of an analog channel (joystick) on a controller.

This function uses the following values of errno when an error state is reached: EINVAL - A value other than E_CONTROLLER_MASTER or E_CONTROLLER_PARTNER is given. EACCES - Another resource is currently trying to access the controller port.

\param id The ID of the controller (e.g. the master or partner controller). Must be one of CONTROLLER_MASTER or CONTROLLER_PARTNER \param channel The analog channel to get. Must be one of ANALOG_LEFT_X, ANALOG_LEFT_Y, ANALOG_RIGHT_X, ANALOG_RIGHT_Y

\return The current reading of the analog channel: [-127, 127]. If the controller was not connected, then 0 is returned

\b Example \code void opcontrol() { while (true) { motor_move(1, controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y)); delay(2); } } \endcode