Limit Switch Programming

So I am trying to program limit switches so my 4 bar doesn’t go too far up and down. I’m doing this to my Double Reverse 4 Bar but only for the way down. I have a pic of the program right now and the 4 bar doesn’t stop when it hits the limit switch, and the DR4B only goes up. Is this my programming issue or a mechanical issue?
Thanks
Pic of Program.PNG

There’s no code
Oh it just loaded

i just posted the code

Lols

The logic is sound, but the syntax is


SensorValue[sensor]

, not


SensorValue(sensor)

. That should fix it.

Ok here’s how I would recommend doing it from current code we have competed with:
if(vexRT[Btn6U] == 1)
{
if(SensorValue(Up4Bar) == 1)
{
motor[L4Bar] = 0;
motor[R4Bar] = 0;
}
else
{
motor[L4Bar] = 127;
motor[R4Bar] = 127;
}
}
else if(vexRT[Btn6D] == 1)
{
if(SensorValue(Down4Bar) == 1)
{
motor[L4Bar] = 0;
motor[R4Bar] = 0;
}
else
{
motor[L4Bar] = -127;
motor[R4Bar] = -127;
}
}
else
{
motor[L4Bar] = 0;
motor[R4Bar] = 0;
}

That’s how I’ve always done it and never had a problem.

I know it’s not pretty… but just see if it works

should the sensor name be in brackets instead of parenthesis

It shouldn’t matter at all.

That doesn’t mean your syntax is correct. RobotC is quite forgiving about these things, but you should still strive to use the correct syntax:


SensorValue]

I never said I was right, just that it shouldn’t matter.

The thing I find odd is that RobotC’s sample programs use SensorValue() while their Online Wiki says “short sensorValue[tSensors sensor]”

As what I can see, there doesn’t seem to be any issues with the code (unless someone can prove me otherwise). When a sensor isn’t connected, there should either be a value of 1 or -1, so probably I think that what’s happening is that either one of your limit switches aren’t connected in the correct port, isn’t plugged in, or a wire could be potentially damaged.
This is just my inference though, but hopefully this helps :smiley:

  • [TVA] Connor

Oh if sensors output 1 or -1 and not 0 or 1 then that’s the problem.

The program unfortunately didn’t work

That’s odd. Did anything happen at all?

Uh the 4 bar continued to go down after hitting the limit switch
NVM it worked. i must have typed it in wrong

Oh wait my program worked?

Ya, but it didnt work for the DR4B
Any clue on why that is?

Debug the values the limit switches output when pressed and unpressed. Make sure the codes calls those values.