We cannot tell you what is wrong with your code as you have not told us what is going wrong. Please post in detail the problems you are experiencing with this program so that we know what to look for.
the code here is not working as intended, I was the motor and pnuematics to react when I press the corresponding button, for the motor R1 and R2. I guess my real question is how should I set up motors and pnuematics to be linked to the controller. Thanks
Currently, your code uses master.get_digital_new_press. This function returns true if the controller button recently changed from unpressed to pressed. This means that once you press the button, it will return true for one iteration of the while(true) loop. However, after that, the function will return false. While you hold R1 or R2, the get_digital_new_press functions will return false, defaulting to the else statement.
else {
shoot = 0;
}
Instead, for controls where you want to hold a button for motor movements, simply use master.get_digital.
hey, I tried your example, however, the motor moves very slow and only moves once every time you press it. Is there a way to toggle and input and make it go at its max speed?
I’m not sure what exactly you are asking, but if you want to use a controller button to toggle a motor on or off, you will need to use a variable to keep track of what the motor is currently doing, as well as using get_digital_new_press. An example would look something like this:
bool toggled_motor_1 = false;
while(true) {
if(master.get_digital_new_press(YOUR_BUTTON_HERE)) {
toggled_motor_1 = !toggled_motor_1 ; // switch our boolean to the other state
if(toggled_motor_1 ) {
// do something for state 1
} else {
// do something for state 2
}
}
}
If you have more than 2 states for your motor, you can use an integer and increment it to keep track of which state you are on.
As for your motor not running at full speed, it sounds like a mechanical issue. running the code motor = 127; will set your motor to max speed code wise, so it sounds like you may be running a red (100rpm) cartridge, the motor is geared down to a low output speed, and/or there is significant friction on the motor.