answer to "limit switch" from 663robotics

drive as normal, but then in the driving loop (usually a while loop or something) check the value of the limit switch, if it is over the edge (i.e. switch is open) then stop all your motors…you should read the programming guide:D

The programing guide has nothing on how to set them up only bumper switches i have only had it since christmas. could you write a code for me or post it (instructions) on here thanks a lot.:slight_smile:

ok ill post code for motor 1 and 2 to go forward until the limit switch goes open, ill try and post it ASAP

ok sorry i couldnt upload the code here it is in C
#include “Main.h”

void main (void)
unsigned char limit1;
while (1==1)
limit1 = GetDigitalInput ( 1 );
if (limit1 == 1) //Detects if the limit switch goes off the table
SetMotor ( 1, 127);
SetMotor ( 2, 127);
SetMotor ( 2, 127);
SetMotor (1, 127);

basically add a unsigned char variable called limit1
make a while loop with a condition of 1==1
use a Input>Limit Switch command that reads pin 1 and gives the value to limit1
then make an if command that reads limit1, condition is limit1==1 then…
make both motors stop with motor commands
drag an else command
make the motors move forward
then click Options>Controller Configuration
and double click pin 1 so it has an inward arrow

You may need to change the pins around

can u do it in easy c if not thanks for trying.

no but the instructions i gave you should work, and all the C is just basic easyC commands

Thanks so just do the samw for easy c and it will probably work?

yes it should work, remember if anything is in a different port then you have to change it

What ports do the motors have to be in? and it is 2wd or4wd?

Motor ports 1 and 2

What motor is the left and what is the right?

im not sure youll have to try each configuration, i didnt actually build the robot for this

OH SORRY u r helping me so much i feel like u know everything:)

Use the code thingy when you are entering code.

hes talking about the user code block

yes this would work too, i forgot about this

I had the same issue, just drag in a limit switch module and I think that’s about it, you need to say what port it is. Just a hint, you can also say limit ==0, ,so if 1 was limit switched pressed in then 0 is limit switch open.

No, I mean:


oh sorry i didnt know that feature of the forum :cool: thats pretty useful, is it like exact formatting or something?