Need bumber switch code

My mobile goal system would be better if we could just press a button and the mechanism would go down until it hits the bumper switch. My team tried to make it so that when it was pushed the bumper switch, the mobile goal pickup would turn off; but I instead need a code that will make the mechanism stop, when pushed, and go no farther. Is this possible? and if so can I have that code?

In this scenario, the bumper switch could easily be replaced with a physical stop, so that it physically cannot go any farther.

However, another possible solution is with a Potentiometer. Just stick one onto the main rotating shaft of your mobile goal lift, find the Potentiometer value when the mobile goal lift is all the way down, and use that value in your code.

Example (say the Potentiometer value is 3000):

void putDownMogo() {
     while(SensorValue[mogoPot] < 3000) {
          motor[mogoLeft] = 127;
          motor[mogoRight] = 127;
     motor[mogoLeft] = 0;
     motor[mogoRight] = 0;

If the mechanism has too much weight so that it can’t maintain itself at that height and just falls down because of gravity, then a physical stop is probably your best option (or a PID control loop, if you’re familiar with them).

ifr you want to use a bumper switch (which I think is a safe assumption since that’s what you asked for) just replace

SensorValue[mogoPot] < 3000



EDIT: nevermind the while loop will make it where you can’t do anything else until the mogo hits the bumper switch

I was going to write a better snippet of code, but I’m on my phone which makes that an annoying task. You can have a function to move the mogo down and have an if statement in which that function will be run if a variable is true. you can set this variable to true if the desired button is pressed in another if statement and to false if the bumper switch is pressed in another if statement. I’ll leave the exact implementation up to you.