So I’m basically trying to create a program where there are two motors (driving motors) and one limit switch, and the function of the program is to have the motors go at half speed when the switch is not pressed in, and to not go at all when it is. My problem is, I can only get the motors to start driving, then stop once I’ve pressed the switch. After I release it, the motors don’t start back up again. How do I get it to do that? I’ve tried a variety of control structures and different programs and this is quite honestly driving me crazy. I know limit switches are usually used on arms and other components to prevent damage; is the problem here my application of the limit switch? I’m lost.
I know this is probably pretty basic and I’m probably overlooking something simple, but any help would be greatly appreciated. Thanks in advance!
Care to post some code? Sometimes it is the simplest of things and your logic is mostly right in the code.
For what you’ve described, all you need to do is put your code in a loop. Here’s some pseudo code that will do what you want.
while(true) //Loops forever
{
if(limit switch is pressed)
Motor = 0;
else //If the limit switch is not pressed
Motor = 63;
}
Remember that all your doing is checking if the limit switch is currently pressed and if it is then you tell the robot to do something (stop). In all other situations you are doing something else (driving). You put this within your main loop.
Sorry to bump this, but I remembered I had made it and figured the solution would help others who have the same issue. Also, an (admittedly very late) thank you to everyone who responded!
Code (with one touch sensor in dgtl9 and two regular 393 motors in ports 3 and 4):
task main()
{
while(1==1)
{
if(SensorValue(tSensor) == 1)
{
motor[port3] = 0;
motor[port4] = 0;
}
else
{
motor[port3] = 63;
motor[port4] = 63;
}
}
}