Trouble with getDigital() in Pros for V5

We are using Pros for v5 for the first time (switched from Vex Coding Studio a few weeks ago), and got most of our user control working (tank drive, lift), however we are having trouble with the Buttons. We are using the getDigital() function which works just fine on our lift and Hdrive wheel, (which are controlled by R1, R2, L1, L2).

However, when coded the same way, the getDigital() does not work with UP, DOWN, A, B. We are sure it is a code issue, since switching ports shows us that each of our components works with the R1,R2, L1, L2 buttons.

See screenshot for our code that is not working (Buttons A and B).
image

Here is a screenshot of working code:image%20(1)

Here is a screenshot of the configuration and drive control.
image

Remove E_CONTROLLER_ from in front of DIGITAL_A and DIGITAL_B.
In other words, your condition in the if statement should be:
master.get_digital(DIGITAL_A)

E_CONTROLLER is the prefix for choosing controllers, not buttons.

We tried that as well, and it did not work.

master.get_digital(DIGITAL_A)

No, @Loan_Wulf is incorrect.

E_CONTROLLER_DIGITAL_A is just the good programming practice, long form of DIGITAL_A.
If you have enabled the short name syntax in your main.h, you can use either.
If it compiles, you should be fine.
https://pros.cs.purdue.edu/v5/api/c/misc.html#digital-l1

As for your issue, I’m not sure what it is.
There should be no reason why UP does not work but R1 works.

The only thing I can suggest is isolate the issue, comment out everything except the lines in question.
Make sure the motors are properly configured, and that you are not setting 0 to the motors somewhere else.
Try switching the lift control to UP and DOWN, to see if the problem is related to the controller, or if its related to your tilter motor configuration or port.

2 Likes

Sorry, I’ve only been using PROS for about a month (I’m a long time Java user). @theol0403 is the expert here. But yeah, I would guess something is wrong with your bot (incorrect ports, etc.) or with your motor variables. As @theol0403 pointed out, this could also occur if you set the motor speed somewhere else that writes over it. That’s definitely one to try out.

1 Like

Can you post the whole section of code? Not just the small snippet?

#include “main.h”
using namespace pros;
//#include “config.h”

/**

  • A callback function for LLEMU’s center button.
  • When this callback is fired, it will toggle line 2 of the LCD text between
  • “I was pressed!” and nothing.
    */
    void on_center_button() {
    static bool pressed = false;
    pressed = !pressed;
    if (pressed) {
    pros::lcd::set_text(2, “I was pressed!”);
    } else {
    pros::lcd::clear_line(2);
    }
    }

/**

  • 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() {
    pros::lcd::initialize();
    pros::lcd::set_text(1, “Hello PROS User!”);

    pros::lcd::register_btn1_cb(on_center_button);
    }

/**

  • 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() {}

/**

  • 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() {
    pros::Controller master(pros::E_CONTROLLER_MASTER);
    pros::Motor front_left_motor(20);
    pros::Motor front_right_motor(11, true);
    pros::Motor intake1(2, false);
    pros::Motor intake2(3, true);
    pros::Motor lift1(5, true);
    pros::Motor tilter(4, true);
    pros::Motor lift2(6, false);
    pros::Motor u_wheel(7, E_MOTOR_GEARSET_18);

    while (true) {

     front_left_motor.move(master.get_analog(ANALOG_LEFT_Y));
    

    front_right_motor.move(master.get_analog(ANALOG_RIGHT_Y));

     if (master.get_digital(DIGITAL_R1)) {
     u_wheel.move_velocity(100); // This is 100 because it's a 100rpm motor
     }
     else if (master.get_digital(DIGITAL_L1)) {
     	u_wheel.move_velocity(-100);
     }
     else {
     	u_wheel.move_velocity(0);
     }
    
     if (master.get_digital(DIGITAL_R2)) {
     lift1.move_velocity(100); // This is 100 because it's a 100rpm motor
     	lift2.move_velocity(100);
     }
     else if (master.get_digital(DIGITAL_L2)) {
     	lift1.move_velocity(-100);
     	lift2.move_velocity(-100);
     }
     else {
     	lift1.move_velocity(0);
     	lift2.move_velocity(0);
     }
    

/* if (master.get_digital(E_CONTROLLER_DIGITAL_UP)) {
intake1.move_velocity(100);
intake2.move_velocity(100);
printf(“Buttons Bitmap: %d\n”, pros::lcd::read_buttons());

} else if (master.get_digital(E_CONTROLLER_DIGITAL_DOWN)) {
  intake1.move_velocity(-100);
  intake2.move_velocity(-100);

} else {
  intake1.move_velocity(0);
  intake2.move_velocity(0);
  }

	*/

if (master.get_digital(E_CONTROLLER_DIGITAL_A)){ 
		tilter.move_velocity(100);
		
} else if  (master.get_digital(E_CONTROLLER_DIGITAL_B)){
  tilter.move_velocity(-100);

	} else {
    tilter.move_velocity(0);
    


}


pros::delay(20);
}

}