Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

Purpose

Get the value of an Analog Channel (joystick) on a remote controller connected to the CrcDuino via a CrcConnect module.

When to use

Whenever you need to use the position of a remote controller joystick or triggers.

Where to use

Most probably in the void loop() part of your .ino file, since we’d usually want to actively monitor the value.

Click here to learn more on the CrcConnect system, that allows to control a CrcDuino using popular off-the-shelf remote controllers.

If not connection is established with a remote controller via a CrcConnect module, ReadAnalogChannel() returns a value of 0. Depending on the application, it might be useful to validate the status of the connection using IsCommValid().

This function requires the use of the following CrcLib functions at some point of your .ino file in order to work properly:

Returns

This function returns the value of the analog channel mentioned as the function’s argument as a signed chartype. The value returned will range between -128 and 127, proportionally to the position of the joystick or trigger. The returned value will be:

  • -128, if the

    • Joystick is at the maximum left position (for x axis channels)

    • Joystick is at the maximum up position (for y axis channels)

    • Trigger is fully unpressed

  • 0, if the joystick/trigger is at the middle position of the axis, or if no connection is established between a remote controller and the CrcDuino (via a CrcConnect Module)

  • 127, if the

    • Joystick is at the maximum right position (for x axis channels)

    • Joystick is at the maximum down position (for y axis channels)

    • Trigger is fully pressed

The Logitech F130 and HAVIT controllers do not support analog gestures of the triggers, in contrary to Xbox and PlayStation controllers.

On an Xbox or PlayStation controller, the value of GACHETTE_L and GACHETTTE_R will range from -128 (trigger unpressed) to 127 (trigger fully pressed).

On the F130 and HAVIT, GACHETTE_L and GACHETTE_R can only take the value -128 (trigger not pressed) or 127 (trigger fully pressed).

When using a Havit Controller, make sure to press the “ANALOG” button on the remote controller to light up the red LED between the joysticks. Else, the value of the joystick can only be {-128, 0, 127}, instead of [-128, 127].

Main prototype and parameters

static int8_t Crc::CrcLib::ReadAnalogChannel(ANALOG channel)

The following parameters must be passed to the function for it to work properly:

  • channel: The name of the joystick channel you want to read the value of. Must be of the type ANALOG.

Overloads

This function does not have any overloads. It can only be used as described by the main prototype.

Examples

 #1: We want to print on the serial monitor the position of the horizontal axis of the left joystick of a wired XBOX 360 controller, connected via a CrcConnect module.
#include <CrcLib.h>

using namespace Crc;

signed char joystickValue;

void setup() {
    CrcLib::Initialize();
    
    Serial.begin(2000000);  //Open the serial Monitor at a 2000000 baud rate
    
    /* 
    The rest of your setup code
    ...
     */
}
void loop() {
    CrcLib::Update();

    joystickValue = CrcLib::ReadAnalogChannel(ANALOG::JOYSTICK1_X);
    Serial.println(joystickValue);
    /* 
    The rest of your looping code
    ...
    */
}

More on this function

There is sadly nothing more to be said about this function…

Related articles

  • No labels

0 Comments

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account.