Adding micro limit switch to limit the movement of the rotation servo

hi

I am using the maestro 6 channel controller.

I would like to use the rotation servo to move a sliding door, and I would like to add a limit switch at the end and at the beginning to limit the servo from going further.

I tried to implement the script examples at your page but the functionality it achieved is not what I am looking for.

I would like the door to open then stop by the limit switch, then close and get stopped by the limit switch again.

the limit switch I am using is the normally closed NC and the common with the 10k um resistor.

I tried to modify the scrept that I took from the examples you have in the website, I did some modidifcations, now this modification, I can stop the rotational servo when I click the button, but then I need to trigger the reverese direction movement when I click the other button, since I am using two buttons.

begin
button_a if sequence_a endif
repeat

sub button_a
 0 get_position 500 less_than
 return


sub sequence_a
10000 2 servo 10 delay
0000 2 servo 10 delay
return

thank you

Hello.

The way your code is right now, it waits for a button press before running the servo through a sequence. To implement a limit switch, you will want to send the servo a target position (which translates to a rotation speed when using a continuous rotation servo), then wait until the limit switch is pressed to stop the servo. For example, the subroutine to move your servo one way might look like this:

sub sequence_a

  8000 2 servo   # tell the servo to start moving in one direction

  begin              # stay in this while loop until the button/limit switch is pressed
    1 get_position 500 greater_than
    while
  repeat

  6000 2 servo    # tell the servo to stop by sending it the neutral position (typically 1.5ms)

return

If you are using the same switch as the limit for both rotations, you can make this sequence run in the opposite direction by changing the 8000 to 4000.

If you try modifying your script to work like this and still have problems, can you post your new script along with a description of what it does?

Brandon