I would like to program my bump switch to restart my entire program whenever it is touched. Does anyone know how to code something like this?
is this for driver control or autonomous?
autonomous
Put your autonomous code inside the user control task, inside an if statement checking for a bump switch press.
Edit: you would also want a while statement to restart auton while its running. so…
if (button == 1)
{
while (button == 0)
{
// auton code
}
}
you can also start the autonomous task in driver control to just run the autonomous function without having to change your code in two places in your program
As written, noting that it takes time to touch and release a switch, wouldn’t that do nothing? You touch the switch to trigger the if statement (button == 1). Now you hit the while loop and button is still 1 since it takes a tiny fraction of a second for the computer to move to the next step, so button==0 returns false and exits the while loop on the first attempt. If C ran the loop before checking the condition, that would be something else, but C checks the condition first. I’m tired after a roughly 13-hour work day with a few hours of chores on top of it, so maybe I’m just not reading well right now.
If you’re just trying to run all your autonomous code on a button press and then return to joystick control (edit: same as @roboeagle15 was suggesting as I wrote):
while (true)
{
if(button==1)
{
// Place autonomous code here.
}
// Place any other checks you want, like joystick controls here or before checking “button”.
delay(20);
}
If you have code after autonomous before the infinite while loop in remote control that you want to also run, you’ll have to do it a little differently, but you could just drop that in the end of the autonomous code above.