Java in RobotC for FTC TeleOp

I need help with programming. I found that you can use certain Java commands in RobotC. So I thought that I could use the Switch command which worked for some things but I have no idea how to make it work for the buttons in the TeleOp phrase.

The syntax for the Switch command is

    switch (*variable*)
       case *condition*:
       case *condition2*:

or Just watch this YouTube video for more detail on the syntax.

This is my proof of concept code for Java in RobotC. It is supposed to display what button is being pressed on the NXT screen. Since this was only a proof of concept, only wrote code for Buttons 1-4 on Game controller #1(Logitech Dual action). The purpose of using the Switch command was to shorten up the code and make it less massive instead of using an IF and ELSE command for every button that will be used.

#pragma config(Hubs,  S1, HTMotor,  HTMotor,  HTMotor,  HTServo)
#pragma config(Motor,  mtr_S1_C1_1,     Intake,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C1_2,     Lift,          tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C2_1,     DriveL,        tmotorNormal, openLoop, reversed)
#pragma config(Motor,  mtr_S1_C2_2,     ShooterR,      tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_1,     DriveR,        tmotorNormal, openLoop)
#pragma config(Motor,  mtr_S1_C3_2,     ShooterL,      tmotorNormal, openLoop)
#pragma config(Servo,  srvo_S1_C4_1,    WingL,                tServoNormal)
#pragma config(Servo,  srvo_S1_C4_2,    WingR,                tServoNormal)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"  //Include file to "handle" the Bluetooth messages.

void initializeRobot()
  servo[WingL] = 127;  // Reset Left wing position
  servo[WingR] = 127;  // Reset Right wing position

task main()

  waitForStart();   // wait for start of tele-op phase
  int buttons = joystick.joy1_Buttons; // shortens the joystick.joy1_Buttons variable
    getJoystickSettings(joystick); //Updates controls
    switch (buttons)
      case 1:  // checks if button 1 on Joy 1 is being pressed down
        nxtDisplayCenteredTextLine(2, "Button : %d", 1);  // Display "Button: 1"
      case 2:  // checks if button 2 on Joy 1 is being pressed down
        nxtDisplayCenteredTextLine(2, "Button : %d", 2);  // Display "Button: 2"
      case 3:  // checks if button 3 on Joy 1 is being pressed down
        nxtDisplayCenteredTextLine(2, "Button : %d", 3);  // Display "Button: 3"
      case 4:  // checks if button 4 on Joy 1 is being pressed down
        nxtDisplayCenteredTextLine(2, "Button : %d", 4);  // Display "Button: 4"
      default: // if nothing is being pressed
        nxtDisplayCenteredTextLine(2, "Button : %d",  );  // Display "Button:  "

Thanks in advanced,

Mason Tran
FTC Team 3385
Lead Programmer

The switch statement is and has always has been a C syntax… Java followed C and has a lot of C syntax incorporated in it. RobotC is just an IDE and user library. It also uses a small executive in the processor.

Thanks for clarifying. But, that wasn’t what I was needed help on. I wanted to know if it was possible for me to use the switch statement instead of using a bunch of IF statements for programming the buttons on the game controller for the TeleOP period.

Possible? Yes.

Probable? No… What variable are you gonna switch on?