Help with Switch logic on Micro Maestro

I need some help/advice on how to get a switch to work with the 6 channel Maestro. None of the examples seem to work for me!
I have a simple script that runs three frames, I want to add a switch to change the order of the frames.

Here is my basic logic.

If switch is OPEN
  500 3968 3968 0 0 0 0 frame_0..5 # Frame 0
  1000 5940 frame_0 # Frame 1
  500 5940 frame_1 # Frame 2
Else
  500 3968 3968 0 0 0 0 frame_0..5 # Frame 0
  1000 5940 frame_1 # Frame 2
  500 5940 frame_0 # Frame 

Seems simple enough but I can’t get it to work. . I have added a switch to channel 2 with a resister as described in the manual. It reads 255.75 or 0.75 via the status tab and works correctly.
What scripting do I need to get the switch to do what I want?
basically just need how to get the switch to operate.

CAN ANYONE HELP, I AM DESPERATE AS I HAVE A DEMO PROJECT DUE THAT IS SUPPOSED TO PROVE THAT THE 6 CHANNEL MAESTRO WORK FOR A BIGGER PROJECT.

Here is copy of the stand alone code without the switch that works for the proper servo actions (does not switch order of servo).

### Sequence subroutines: ###

# Sequence 0
sub Sequence_0
  500 3968 3968 0 0 0 0 frame_0..5 # Frame 0
  1000 5940 frame_0 # Frame 1
  500 5940 frame_1 # Frame 2
Quit  
return

sub frame_0..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

Hello.

It looks like you have done everything except reading channel 2 (where you have your switch connected). To do this, you can use the GET_POSITION command. For example, you can check the state of the switch on channel 2 by using “2 get_position” in your script. Then, you can compare this to a value between the two states of your switch to see if it is above or below. This can be done with the “LESS_THAN” or “GREATER_THAN” commands. Since those commands will return a 1 or 0 (depending on the state of the switch), you can put your if statement directly after it. You can find more information about the scripting language commands in the “Command Reference” section of the Maestro user’s guide.

If you try adding this to your script and need additional help, could you post the script you have so far?

-Brandon

Thanks for your help. I spent more time than wanted :slight_smile: but I have the following script running without errors. If you see something I omitted or that can removed, please let me know. :smiley:
Here is the working script commands:

500 3968 3968 0 0 0 0 frame_0..5 # Frame 0  #Lock all servos closed
2 get_position
100 less_than
if
  1000 5940 frame_0 # Frame 1		#Open Servo 0
  500 5940 frame_1 # Frame 2		#Open Servo 1 after 1 second delay
else
  1000 5940 frame_1 # Frame 2		#Open Servo 1
  500 5940 frame_0 # Frame 1		#Open Servo 0 after 1 second delay
endif
quit


sub frame_0..5
  5 servo
  4 servo
  3 servo
  2 servo
  1 servo
  0 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

sub frame_1
  1 servo
  delay
  return

I am glad you were able to get it working. Thank you for sharing your script. It looks like you only use channel 0 and channel 1, so you can probably get rid of the first four lines in your “fram_0…5” subroutine, along with the four zeros in the first line of your script. Setting the servo channels to 0 is just disabling them; if you are not using servos on those channels, you can omit those lines.

By the way, I noticed you are using 100 when you are checking the state of your switch. This will probably work for your application, but it might be good to point out that the values you see for an input channel in the “Status” tab (0-255) correspond to numbers from 0 to 1023 in your script. If you wanted to use a more centered number, you could try something around 500.

-Brandon