Using 2 push buttons to start/stop code

I am doing a project for college in which our group has to build a robot that moves on its own and dodges obstacles in its surroundings using proximity sensors.

I need to incorporate 2 push buttons that will start and stop running the code (note: they are push buttons, not toggle buttons). I am a beginner with arduino so I only have a vague idea on how to make this work. Could anyone give me some tips on how to make the code? (or give me some example code, anything that helps)

I would have a look at this state change detect example. You will see how to act upon each new press or new release (if the latter is necessary.)

So when you detect a new press of button 1, do thing 1 ; new press of button 2, do thing 2.

I actually save a slimmed down version of that as a bit of a template: I took out the part where it does the counting.)

One suggestion: I changed the example's pinMode from INPUT to INPUT_PULLUP, and wire my buttons from pin to ground, not pin tom 5V. Much easier to use the internal resistor. It reverses the logic though, so a pressed button is low and un-pressed is high.

Thank you, that helps! Much appreciated :money_mouth_face: