Skip to content

Advanced Remote Functionality

Jeffrey Shen edited this page Jul 24, 2017 · 1 revision

RobotC's support for the remote only gives a signal based on whether buttons are pressed or not. There is no native support if a user wants to execute only one function every time a button is pressed (push-release functionality) and the user cannot detect if a button is long held.

Setup

In config.c:

#define USE_PR_BUTTONS 1
#define NUM_PR_BUTTONS [insert the number of buttons you want to track here]

You also need to define a method setUpButtons() which tells the library which buttons you want to track.

void setUpButtons(){ 
  addPrButton(0, Btn5D); 
  addPrButton(1, Btn5U); 
  ...
}

This method should be filled up with addPrButton() calls to properly initialize each button.

  • The first parameter of addPrButton is the INDEX. This is a number in the range [0, NUM_PR_BUTTONS), that is not already the index of another button. It will be used to access this specific button's value later.
  • The second parameter of addPrButton is the BUTTON NAME. This tells the library which button on the remote you want to be mapped. Only use buttons, not channels.

Usage

To actually access the values of each button, call getPrButton(INDEX) which returns three possible values:

  • 0: The button is not any of the other states
  • PUSHED_RELEASED (which equals 1): The button has been pushed and released
  • LONG_HELD (which equals 2): The button has been held for at least 1 second and then released

After the button's value has been accessed, and a function is performed, the value of the button must be reset by calling resetPrButton(INDEX). This ensures that the remote functions continue working as normal.

Example

Inside while loop in user control:

if(getPrButton(0) == LONG_HELD){
  //Execute amazing function here!
  resetPrButton(0);
}