Subsystem Toggling
Last updated
Was this helpful?
Was this helpful?
#include "main.h"
pros::Motor motor(1);
pros::Controller master();
bool move = false; // by default, this will not move
void opcontrol() {
while(true) {
if(master.get_digital_new_press(pros::Digital_B)) {
// If this is true, move will changed to false
// and vice versa.
move = !move;
}
// If move is true, move the motor.
if(move) {
motor.move(100);
}
// Else, don't
else {
motor.move(0);
}
pros::delay(20);
}
}
vex::motor mtr(vex::PORT1);
void Motor_Move() {
mtr.spin(vex::directionType::fwd, 100);
}
bool prev_value = false;
bool move = false;
int main() {
// Since VEXCode doesn't have an equivalent function to
// get_digital_new_press, we need to detect the new push
// of a controller button.
while (1) {
prev_value = Controller1.ButtonB.pressing();
// Detect a new press
if(prev_value == false && Controller1.ButtonB.pressing()) {
move = !move;
}
if(move) {
mtr.spin(vex::directionType::fwd, 100);
}
else {
mtr.spin(vex::directionType::fwd, 0);
}
wait(20, msec);
}
// OR
// Alternatively, VEXCode also supports
// callbacks bound to controller buttons
//
// DO NOT put this in a while loop, call before a
// while loop unlike this example.
Controller1.ButtonB.pressed( Motor_Move );
}