PROS Controller Buttons Not Working

Hi! I am trying to code using PROS with EZTemplate for the first time. I am having trouble with the controller buttons. I have them coded but nothing is happening when I press them! I don’t know what to do - here is my main.cpp code:

#include "main.h"


// Chassis constructor
Drive chassis (
  // Left Chassis Ports (negative port will reverse it!)
  //   the first port is the sensored port (when trackers are not used!)
  {-8, -5, -7}

  // Front - 8
  // Middle - 5
  // Back - 7


  // Right Chassis Ports (negative port will reverse it!)
  //   the first port is the sensored port (when trackers are not used!)
  ,{18, 14, 17}

  // Front - 18
  // Middle - 14
  // Back - 17

  // IMU Port
  ,9

  // Wheel Diameter (Remember, 4" wheels are actually 4.125!)
  //    (or tracking wheel diameter)
  ,2.75

  // Cartridge RPM
  //   (or tick per rotation if using tracking wheels)
  ,600

  // External Gear Ratio (MUST BE DECIMAL)
  //    (or gear ratio of tracking wheel)
  // eg. if your drive is 84:36 where the 36t is powered, your RATIO would be 2.333.
  // eg. if your drive is 36:60 where the 60t is powered, your RATIO would be 0.6.
  ,0.75


  // Uncomment if using tracking wheels
  /*
  // Left Tracking Wheel Ports (negative port will reverse it!)
  // ,{1, 2} // 3 wire encoder
  // ,8 // Rotation sensor

  // Right Tracking Wheel Ports (negative port will reverse it!)
  // ,{-3, -4} // 3 wire encoder
  // ,-9 // Rotation sensor
  */

  // Uncomment if tracking wheels are plugged into a 3 wire expander
  // 3 Wire Port Expander Smart Port
  // ,1
);



/**
 * Runs initialization code. This occurs as soon as the program is started.
 *
 * All other competition modes are blocked by initialize; it is recommended
 * to keep execution time for this mode under a few seconds.
 */
void initialize() {
  // Print our branding over your terminal :D
  ez::print_ez_template();
  
  pros::delay(500); // Stop the user from doing anything while legacy ports configure.

  // Configure your chassis controls
  chassis.toggle_modify_curve_with_controller(true); // Enables modifying the controller curve with buttons on the joysticks
  chassis.set_active_brake(0); // Sets the active brake kP. We recommend 0.1.
  chassis.set_curve_default(0, 0); // Defaults for curve. If using tank, only the first parameter is used. (Comment this line out if you have an SD card!)  
  default_constants(); // Set the drive to your own constants from autons.cpp!

  // These are already defaulted to these buttons, but you can change the left/right curve buttons here!
  // chassis.set_left_curve_buttons (pros::E_CONTROLLER_DIGITAL_LEFT, pros::E_CONTROLLER_DIGITAL_RIGHT); // If using tank, only the left side is used. 
  // chassis.set_right_curve_buttons(pros::E_CONTROLLER_DIGITAL_Y,    pros::E_CONTROLLER_DIGITAL_A);


  // Initialize chassis 
  chassis.initialize();
 
}



/**
 * Runs while the robot is in the disabled state of Field Management System or
 * the VEX Competition Switch, following either autonomous or opcontrol. When
 * the robot is enabled, this task will exit.
 */
void disabled() {
  // . . .
}



/**
 * Runs after initialize(), and before autonomous when connected to the Field
 * Management System or the VEX Competition Switch. This is intended for
 * competition-specific initialization routines, such as an autonomous selector
 * on the LCD.
 *
 * This task will exit when the robot is enabled and autonomous or opcontrol
 * starts.
 */
void competition_initialize() {
  // . . .
}



/**
 * Runs the user autonomous code. This function will be started in its own task
 * with the default priority and stack size whenever the robot is enabled via
 * the Field Management System or the VEX Competition Switch in the autonomous
 * mode. Alternatively, this function may be called in initialize or opcontrol
 * for non-competition testing purposes.
 *
 * If the robot is disabled or communications is lost, the autonomous task
 * will be stopped. Re-enabling the robot will restart the task, not re-start it
 * from where it left off.
 */
void autonomous() {
  chassis.reset_pid_targets(); // Resets PID targets to 0
  chassis.reset_gyro(); // Reset gyro position to 0
  chassis.reset_drive_sensor(); // Reset drive sensors to 0
  chassis.set_drive_brake(MOTOR_BRAKE_HOLD); // Set motors to hold.  This helps autonomous consistency.


}

static bool SlapperMoveBool = false;
static bool WingsToggleBool = false;
static bool LiftToggleBool = false;

void IntakeMove(){

  if(pros::E_CONTROLLER_DIGITAL_R1){
    Intake.move(60);
  }
  else if(pros::E_CONTROLLER_DIGITAL_R2){
    Intake.move(-60);
  }
  else{
    Intake.move(0);
  }
}

void Hang(){

  if(pros::E_CONTROLLER_DIGITAL_X){
  Ratchet.set_value(true);
  Lift.set_value(false);
  }
  
}   

void TrustOut(){
  if(pros::E_CONTROLLER_DIGITAL_DOWN){
    Trust.set_value(true);
  }
}

void SlapperToggle(){
  if(pros::E_CONTROLLER_DIGITAL_L2){
  SlapperMoveBool = !SlapperMoveBool;
  pros::delay(300);
  }
  else if(SlapperMoveBool == true){
    Slapper.move(60);
  }
  else{
    Slapper.move(0);
  }

}

  void WingsToggle(){
    if(pros::E_CONTROLLER_DIGITAL_L1){
      WingsToggleBool = !WingsToggleBool;
      pros::delay(300);
    }
    else if(WingsToggleBool == true){
      Wings.set_value(true);
    }
    else{
      Wings.set_value(false);
    }
  }
  
  void LiftToggle(){
    if(pros::E_CONTROLLER_DIGITAL_UP){
      LiftToggleBool = !LiftToggleBool;
      pros::delay(300);
    }
    else if(LiftToggleBool == true){
      Lift.set_value(true);
    }
    else{
      Lift.set_value(false);
    }
  }









/**
 * Runs the operator control code. This function will be started in its own task
 * with the default priority and stack size whenever the robot is enabled via
 * the Field Management System or the VEX Competition Switch in the operator
 * control mode.
 *
 * If no competition control is connected, this function will run immediately
 * following initialize().
 *
 * If the robot is disabled or communications is lost, the
 * operator control task will be stopped. Re-enabling the robot will restart the
 * task, not resume it from where it left off.
 */


void opcontrol() {
  // This is preference to what you like to drive on.
  chassis.set_drive_brake(MOTOR_BRAKE_HOLD);
 



  while (true) {

    chassis.tank(); // Tank control
    // chassis.arcade_standard(ez::SPLIT); // Standard split arcade
    // chassis.arcade_standard(ez::SINGLE); // Standard single arcade
    // chassis.arcade_flipped(ez::SPLIT); // Flipped split arcade
    // chassis.arcade_flipped(ez::SINGLE); // Flipped single arcade

    // . . .
    // Put more user control code here!
    // . . .

    LiftToggle();
    SlapperToggle();
    WingsToggle();
    IntakeMove();
    Hang();
    TrustOut();

    
    pros::delay(ez::util::DELAY_TIME); // This is used for timer calculations!  Keep this ez::util::DELAY_TIME
  }
}


Yes - I have the functions identified in main.h and my devices are identified in another header file. The drive chassis is working but nothing else. I checked ports too

Thank you :slight_smile:

Try taking a look at the pros docs for the controller here: https://pros.cs.purdue.edu/v5/api/cpp/misc.html#get-digital. The example there should help you figure out what’s wrong with your current code. (Hint: look at the condition of the if statement in their example versus your current code)

1 Like