Programming help

I would like to make a program using a bumper switch that runs a set of commands but will stop and do something else if the bumper is pressed… So far, no matter what I try, it only ends up going through the whole first set and then if the bumper is pressed will it go through the second set of commands. To reiterate; I want a program that will start running a set of commands but as soon as the bumper is pressed start going through the next set. Any ideas on what I should do? (I am using Easy C V4 cortex) Thank you in advance and have a good season!

You haven’t shown your code, or any of the things you have tried to do.
You have not even described what you tried to do, only that whatever that was, it failed to do what you want. Therefore, I think your problem is on line 7. Or look at 1103 code (Titan) in the code repository, thats got a lot of examples of complex coding.

But seriously…
“as soon as” can mean an interrupt, but it is often good enough to be
“as soon as I notice that” which is a polling technique as shown below in the
while(polling condition){ sense and reaction loop }

Here is one example of pseudo code that meets your description:

 while( bumper not pressed) {
   // do the first set of commands
    read line sensors
    set motors to follow the line
 } // end while
// the button must be pressed now, because we exited!
// start the second set of commands
 stop wheels motors that were causing us to bump into something
 start motors to unload manipulator
 wait 2 seconds
 stop all motors

I’m sorry for not posting what you explained, however I tried what I felt was too many different types of programs/combinations etc to put them all in the post while trying to remain concise. I wanted to explain my problem and look for others to give me solutions that worked for them without restricting them to things I had already done, after all I could have done it wrong. That being said, thank you for your response and your help :smiley:

I’m not sure you can easily achieve this in EasyC without surrounding every statement with a conditional check on the state of the bumper switch. The switch could be monitored with an interrupt watcher so that once triggered all the following conditional checks will fail.

In RobotC you would do this with multitasking and is quite easy.

Too concise doesn’t help either. Repeating the same thing isn’t concise.
“give me solutions” isn’t always what you get here.
Showing you are making an effort to learn and understand (by posting your code, and what you have tried) is often an effective way to motivate others to reply.
Its the nature of forum replies that sometimes,
no one will answer a simple question,
but many people will point out a wrong answer.

Your example also doesn’t have any background.
Is it a homework problem?
Is it for a VRC autonomous routine?