How to Use the VEX LCD Display

The VEX LCD Screen is obviously useful for debugging display, but it is also possible to read the state of the 3 buttons. It's not very well documented though, so here's what I've figured out:

RobotC has a system variable "nLCDButtons," which is used as a bitmask.
The "RobotCIntrinsics.c" file has the definition of the flags:

typedef enum
{
	kButtonNone     = 0x00,
	kButtonLeft     = 0x01,
	kButtonCenter   = 0x02,
	kButtonRight    = 0x04,
	kButtonExit     = 0x08,
	kButtonExit2    = 0x10,
} TControllerButtons;

So here is a function that queries the mask (two separate lines necessary due to RobotC's compiler):

bool checkLCDButton(TControllerButtons but)
{
   int masked = nLCDButtons & but;
   return (masked == but);
}

 

Usage

To check if the center button is pressed:

bool centerPressed = checkLCDButton(kButtonCenter);

Since it's a bitmask, you can check if the center button AND the right button is pressed by either:

bool method1 = checkLCDButton(kButtonCenter) && checkLCDButton(kButtonRight);

OR

bool method2 = checkLCDButton(kButtonCenter | kButtonRight);