RobotC Gamepad Library

Controlling an NXT with a gamepad in RobotC isn’t too difficult, but it does require some more advanced programming techniques.  Most programmers end up creating some helper functions and variables that they copy and paste throughout their projects, and here is my “library”.

LINK

Gamepad Layout

Example:

//RobotC Joystick Helper Example Source
//    Created By:        Mike Moss
//    Modified On:       01/09/2013

//Joystick Helper Code
#include "joystick_helper.c"

//Our Program
task main()
{
    //Do Forever
    while(true)
    {
        //Get Gamepad States
        js_update();

        //Move motor A with the X button on joystick 1
        if(js_button(1,js_x)==true)
        {
            motor[motorA]=100;
        }

        //Move motor C with the up arrow on the dpad (0 is up, 2 is right, 4 is down, etc...)
        if(js_dpad(0))
        {
            motor[motorC]=100;
        }

        //Move motor B based on the Y axis on the left thumb stick
        //    of joystick 2 with a deadzone of 15
        motor[motorB]=js_lthumb_y(2,15);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>