Limit switch not working properly.

We want to use two limit switches to control a motor in forward and in reverse.

The limit switches are actuating on all channels of the digital sidecar, it does not matter which port we plug it into. We want the switch to stop the individual motors from running. We have tried both constructors (channel only, as well as slot and channel) with the same results. Our code is:


DigitalInput *limitSwitchReverse;
DigitalInput *limitSwitchForward;

// Ctr using only channel
limitSwitchReverse = new DigitalInput(13);
limitSwitchForward = new DigitalInput(14);

// Alternative: Ctr using slot and channel
//limitSwitchReverse = new DigitalInput(4, 13);
//limitSwitchForward = new DigitalInput(4, 14);


if (btn1)
{
	if(limitSwitchReverse->Get() == 0)
	{
		device->Set(Relay::kOff);
	}
	else
	{
		device->Set(Relay::kReverse);					
	}
}
else if (btn2)
{
	if(limitSwitchForward->Get() == 0)
	{
		device->Set(Relay::kOff);
	}
	else
	{
		device->Set(Relay::kForward);					
	}
}
else 
{
	device->Set(Relay::kOff);
}


could someone please post a sample code which demonstrates the correct way to use a limit switch connected to the Digital I/O, to interrupt a spike connected to the Relay.

Thanks

class RobotDemo : public SimpleRobot
{
DigitalInput *switch1;
}

public:
RobotDemo(void):
{
switch1 = new DigitalInput(4,2);//4 is the modual in cRio and 2 the input port
}

that is initializing it but you need to do the rest. you will get a 1 or 0 and need to declare a bool variable to take the number from it in the form

variable = switch1->Get();
or
use switch1->Get() in your conditional

hope it helps

  1. we tried what you said, even though the logic wasn’t any different than our original, and we still had the same results.

  2. we also found that when we actuate the limit switch, it not only blocks all relays but also all the PWM outs.

2 quick things you have things in the code posted that are not declared and things. if you posted the whole thing then i might be able to help better. sometimes there are just miniscule errors that someone else can see but you can’t.

for the second thing how do you get the code to go into that grey box thing

grey box thing? CRio?

no i mean on the forum where it says code and has the grey box of code

code:
(grey box with code)

oh, haha sry. well we figured out was was wrong, we had some crossed wires… but thank you for your help

good luck