Can a program block be run in response to transmitter action

Can an action on the transmitter (for example pressing one of the channel buttons on the back) cause a block of program code to run in the same way that tripping a sensor could? If so, a simple example would be helpful.

**Yes. The code would react to a button being pushed on the transmitter the same as if a switch is actuated on the robot, with an IF statement. That is; “if” this event happens - run this block of code “else” run this block of code. Here is an example from the Vex Starter Code - user_routines.c found on our Downloads page.

  if (rc_dig_in15 == CLOSED)  //When Jumper 15 is on CONFIGURATION C is selected
  {
    pwm07 = pwm02;            //CONFIGURATION C 
    pwm08 = pwm03;
  }
  else                        //CONFIGURATION A & B 
  {
    pwm07 = ~pwm05;
    pwm08 = ~pwm06;
  }

} /* END Default_Routine(); */

Here 2 different sections of code will be executed depending on jumper 15.**


Ricky Torrance
Electrical Engineer
VexLABS

Regarding the code you suggested previously (see below), what type of variable should be declared to read the input (int, etc??)

int rc_dig_in15
rc_dig_in15 = GetRxInput ( 1 , 1 ) ;

Is the above correct?
I don’t understand your use of CLOSED as a value.

**The following section of code is found in user_routines.h file which defines CLOSED.


/* Used in limit switch routines in user_routines.c */
#define OPEN        1     /* Limit switch is open (input is floating high). */
#define CLOSED      0     /* Limit switch is closed (input connected to ground). */

The following section of code is found in user_routines.c file which will run 2 different sections of code based on the Channel 5 and 6 Channel Button.


  pwm05 = 0x7F;               //Handle Channel 5 receiver button
  if (PWM_in5 < BUTTON_REV_THRESH)
    pwm05 = 0xFF;
  else if (PWM_in5 > BUTTON_FWD_THRESH)
    pwm05 = 0;

  pwm06 = 0x7F;               //Handle Channel 6 receiver button
  if (PWM_in6 < BUTTON_REV_THRESH)
    pwm06 = 0xFF;
  else if (PWM_in6 > BUTTON_FWD_THRESH)
    pwm06 = 0;

And things are defined in the same file with the following section of code:


#define BUTTON_REV_THRESH       100
#define BUTTON_FWD_THRESH      154
#define NEUTRAL_VALUE                 127

These examples are for using MPLAB and not easyC. **


Ricky Torrance
Electrical Engineer
VexLABS