Programming Bumper Switches

I am confused with bumper switch programming. I am using 4 bumper switches for different autonomous and I am using EasyC v4 for cortex for programming.

I tried the code below, but it doesn’t work (The variables for all the bumper switches is ‘unsigned char’) -

Bumper1 = GetDigitalInput (5);
Bumper2 = GetDigitalInput (6);
Bumper3 = GetDigitalInput (7);
Bumper4 = GetDigitalInput (8);

{
if (Bumper4 == 1)
{
Wait (50);
LeftAuto();
}

    else if (Bumper3 == 1)
    {
        Wait (50);
        RightAuto();
    }

    else if (Bumper2 == 1)
    {
        Wait (50);
        ThirdAuto();
    }

}
}

Additional info-
I’ve tried “Bumper(number) == 2” but it doesn’t work too.

Can anyone please help me with the code?

Are your Digital Ports set to Input? Press F5 to check the controller configuration.

Yes, in controller configuration, I have written Bumper1, Bumper2, etc. in front of the right digital pin. But does it matter?

This is going to sound stupid, but I believe that bumper switches are 1 when NOT pushed, and 0 when pushed. Which would make your code not work.

Try switching all of your statements to be (if BumperX == 0) and see how that goes.

EDIT: I have been informed that I am, in fact, an idiot. Those are Jumpers.

one problem you have is that you are using an unsigned variable when your variable is always going to be positive. unsigned is used for negative and positive variables. Secondly, you are using a char which happens to be short for “character” and your values are integers so you should be using an “int.” The else if loops dont worry me too much but I would just use if loops.

I think that you are right… I’ll try doing that

Potentiometer is much easier to switch autonomous programs

i agree, it works well, but if you want, bumper switches/limit switches (touch) can be used easily …

if(sensorvalue[bumper1] == 1)
{
integervalue = 1
}

while(integervalue ==1)
{
run autonomous
}

something like that should work !