Programming Bumper Switches

I know how to program a bumper switch and make it do preprogrammed operations. I can include 1 bumper switch in my autonomous code but I do not know how to include multiple Bumper switches in one autonomous code.

Can anyone please help?

What application are you using to code? EasyC or RobotC?

Please use the following thread for, well, simple programming questions. You will likely find that many of them are already answered and if not feel free to ask there.

Another question: what is your goal of using the bumper switches? Is it you push one button to make Autonomous A run, push another to make Autonomous B run, and push both buttons to make Autonomous C run? Or are you thinking of something else?

I am using easyC v4 for cortex and I want the each bumper switch to run a different autonomous.

You can retrieve each bumper to a different variable (like you did with the first one), and then use a series of if statements.

Here is some pseudo code:

bumperOne = BumperSwitch[port1];
bumperTwo = BumperSwitch[port2];
if(bumperOne == 1) {
    AutonomousOne; // run the first autonomous
if(bumperTwo ==1) {
    AutonomousTwo; // run the second autonomous

You can add more bumper switches as you need them. If this is not what you have in mind, can you share your code that you currently have?

But doesn’t “bumperOne == 1” mean that when “Bumper Switch is not pressed…”?

In the programming world 1 generally indicates “true” or “yes” and 0 “false” or “no”

In other words, bumperOne will be 1 when it IS pressed, and 0 otherwise.

You are both right! However EasyC on the Cortex reads digital inputs weirdly, and a pressed bump switch will yield a 0 value (so backwards from what you might think). For what it’s worth, the way drdanielfc and edjubuh describe would work for ROBOTC…

Whoops my bad just assumed EasyC would do it the same way as RobotC.

That’s actually really weird though… it’s so against convention :mad:

Not weird, it’s standard behavior.

Digital port is configured as input with pullup resistor.

When the switch is open the the digital input is pulled high by the resistor and reads as “1”. When the switch is closed then the digital input is connected to gnd (0V) and reads as “0”. This is how ROBOTC will treat the port if it is configured as an input of type “sensorDigitalIn”, ROBOTC inverts this logic internally if you configure the port as type “sensorTouch”.

This is how almost every micro-controller input port works.

Well, I feel obliged to say that it is after all pseudo code. I generally think of 1 being pressed. I know that easyC and ROBOTC exchange what 1 means. I regularly have to switch between the two, so sometimes I forget which is which :o . And for you ROBOTC users, might I recommend using SensorBoolean] for your bumper/limit switches. True is pressed and false is not, it might make your life slightly easier.

Well this is exactly why I would expect 1 to be pressed, because 1 is true so you could do

if (sensorValue[whatever])
// do something

and just treat it as a boolean. This is the behavior in RobotC and most languages but vex is the only microcontroller I’ve ever used so I wasn’t aware that convention is opposite of what one might expect.