Drivetrain.drive(forward);
if (BumperA,pressing()) {
Drivetrain.stop(brake);
}
or
if (BumperA,pressing()) {
Drivetrain.stop(brake);
}
Drivetrain.drive(forward);
also, is ‘.pressing’ the correct command or should it be ‘.pressed’?
when I tried:
if (BumperA.pressed()) {
Drivetrain.stop(brake);
}
the compiler said ‘too few arguments to function call, single argument ‘callback’ was not specified’
what is the difference between .pressed() and .pressing()? I do not have the sensors currently so I have no way of experimenting with it. Will . pressing or .pressed cause the code to not allow robot to go into reverse and continue with the code?
This will tell the robot to drive forward and if the bump switch is triggered, it will stop the drivetrain.
This will tell the robot that if the bump switch is triggered, then stop. If it is not triggered, it will drive forward. If you have this in a while loop they are essentially the same thing. I would recommend doing this instead:
This will tell the program to continually run through the program to check if the bumper switch is triggered and if not, it will continue to drive forward. Your program had no else statement so in the case the bump gets triggered then untriggered, it would remain stuck in the if statement saying to stop.
.pressing() is better, I can’t remember off the top of my head why, but a quick search should tell you.
.pressed() calls a function and does so only on one press. For example, when you are typing, if you were to press and hold the “A” key down, it would only print 1 “A” on the screen. If you let go and pressed again, it would print another.
.pressing() returns a boolean (so tells the computer if a button is being pressed). This doesn’t seem too different, but this can’t call another function and is primarily used for things like “if” and “while” loops as well as boolean variables. An example of this is if you were to press and hold the “A” key down when typing, it would continue printing the letter “A” until you stop holding the key down (like how a computer normally works).
E: .pressed() only needs to be called once (it acts as its own task/thread, I believe) whereas .pressing() needs to be constantly checked (most likely through a while loop).
This is completely dependent on how/what you code.