NXT Functions Buttons

From ROBOTC API Guide
Revision as of 19:52, 18 April 2012 by Bfeher (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


There are four buttons on the NXT front panel. The LEFT, ENTER and RIGHT buttons are on the top row and the EXIT button is on the second row.

Normally, when a program is running, the LEFT and RIGHT buttons are used to toggle between various standard displays. And the EXIT button is used to stop execution of the user program. These characteristics can be overwritten so that button actions can be controlled within a running application program. There are several sample programs (e.g. Centipede, Tetris) included in the ROBOTC distribution that utilize application program control over buttons.


Color Key
Function:
Variable:


nNxtButtonPressed

TButtons nNxtButtonPressed
(TButtons) Contains the number (0 to 3) of the button that is currently depressed. -1 indicates no button is currently pressed. Note that only one button press can be recognized at a time. This is a limitation in the NXT hardware. It is unable to recognize multiple button presses.

0 = Gray Rectangle button. 1 = Right Arrow button. 2 = Left Arrow button. 3 = Orange Square button.

if(nNxtButtonPressed == 1)                        // if the current pressed button is 1 (the Right Arrow):
{
  nxtDisplayCenteredBigTextLine(3, "RIGHT ARROW");  // display on line 3, a big, centered, message
}


nNxtButtonTask

word nNxtButtonTask
(word) The variable serves two purposes. A negative value (default is -1) indicates that the standard firmware processing of NXT buttons should be used. Values in the range of 0 or higher indicates that application program will process buttons. If the value is in the range 0 to 9 (i.e. a valid task number) then this task will be started (or restarted) whenever a button press is detected.
nNxtButtonTask = 2;  // restart task 2 every time a button is pressed


nNxtExitClicks

word nNxtExitClicks
(word) Holds the number of 'clicks' of the EXIT button required to abort a program. Default value is one for compatibility with standard firmware. This variable allows end user programs to use the EXIT button. If you set the variable to 'N' (where 'N' is greater than 1) then the first 'N-1' consecutive clicks of the EXIT button can be handled by the application program. On the N-th consecutive click the firmware will automatically EXIT (i.e. end) your program. Having the firmware perform the check ensures that, even if there is an error in your program, you can always EXIT your program. But it also easily allows your program to have access to the EXIT button. NOTE: With the standard firmware, the EXIT button is not accessible to your program!
nNxtExitClicks = 3;  // triple clicking EXIT button will terminate program