Unsure on how to program limit switch...

Hello there,

So I have looked at how to program limit switch however when I followed this code, it didn’t work on my robot…

So here is my code in operator control…

Imgur

Hope you can help !

There’s no code here that uses a limit switch? What are you trying to accomplish?

Yes, that is why I am asking someone to add the code in for me because I have had issues doing it myself…

What are you trying to program. There are lots of ways to use ‘a limit switch’.

OK so the limit switch is so that our linear doesn’t go down to far as this can then break the chain and strain the motors…

I haven’t used EasyC, but here is a very simple principle that should work. Instead of just having the block to control the motor, put that in a switch. If the switch on the bottom is not pressed allow it to go down, else nothing. And then the same for a switch on the top for going up.

Would you be able to send me a picture of what you mean?

As I said, I have never used EasyC, so I can’t give an example. Try to figure it out, it really isn’t that hard, and if you are having issues with this perhaps try to use help, tutorials, etc. to learn it as you won’t always have people give you code.

I don’t have easyC V4, but here’s some rough psuedocode to demonstrate what you’ll need to do.

while(1==1)
{
	doOtherThings();
	JoystickDigitalToMotor(/*Parameters to wire UP button to UP (no DOWN functionality here)*/);
	char limitSwitchValue = getLimitSwitch();
	if(limitSwitch == PressedValue)
	{
		JoystickDigitalToMotor(/*Parameters to wire DOWN button to DOWN*/);
	}
}

So the general idea is that if the lift is going going up then ignore the limit switch and allow the lift to more, if the lift is going down then only allow it to go down if the limit switch is not tripped. There are two ways (perhaps more) to do this in EasyC.

These examples assume that 127 make the lift go up, limit switch is on port 8 (and untested code).

  1. The simple way. Use the JoystickDigitalToMotorAndLimit block
    [ATTACH]8590[/ATTACH]

  2. The “advanced” way. Read the joystick and essentially use the same code that in the above block.
    [ATTACH]8591[/ATTACH]
    limit2.jpg
    limit1.jpg