Micro maestro / servo / 3 position switch programming help

hello all,
I am completely new to programming/servos and could use a little help with what i think is a simple project. the project is to have a 3 position switch move the servo to 3 set positions. when the switch is flipped up i need the servo at 0 degrees, switch in the middle position i need 90 degrees and switch down 180 degrees.

i have a micro maestro 6-channel servo controller wired to a generic servo and a 3 position switch. i have the servo wired to channel 2, i have a pull up resistor from the 5v out to channel 0 then out to one pole of the switch. and another resistor to channel 1 with that one going to the other pole of the switch. the center position of the switch is common ground.

Edit: used wrong channel numbers.
the logic i’m trying for is:
switch up , channel 0 LOW, channel 1 HIGH, servo 0 degrees
switch middle , channel 0 HIGH, channel 1 HIGH, servo 90 degrees
switch down , channel 0 HIGH, channel 1 LOW, servo 180 degrees

i hope this makes sense and it’s an easy code. i looked at the multiple button example and couldn’t figure out how to change it to what im trying to do.

Hello.

It sounds like you have already wired up your 3-position switch. If you have not done so already, you should configure channels 1 and 2 as inputs (the two that you have your switch connected to) in the “Channel Settings” tab of the Maestro Control Center. Once you have done that, you should make sure the switch functions as you described by monitoring the “Status” tab while toggling the switch.

As for the script, one way you could do something like you described is to use two nested if statements. Since there is only one case where channel 2 would be low, I would start with that. For example:

  2 get_position   #check channel 2
  500 less_than 
  if  #if it is low
    8000 0 servo  #set target of servo to 2ms

Then you can check channel 1 inside of an else statement, so it will only check channel 1 if channel 2 is high. If channel 1 is high, set the servo to the midpoint, and if it is low set it to the other extreme. For example:

else  #if it is high
    1 get_position  #check channel 1
    500 less_than
    if  #if it is low
      4000 0 servo  #set target of servo to 1ms
  
    else  #if it is high
      6000 0 servo  #set target of servo to 1.5ms

    endif
  endif

There are a few things to note about the segments of script that I posted. You might need to adjust the value you are comparing your switch positions to something more appropriate for your switch. Also, I used target positions of 1ms, 1.5ms, and 2ms (which is standard for hobby RC signals). You might need to adjust that to get your desired motion. Many servos are specified to work with a maximum range of motion between 0 and 180 degrees with a plus or minus 10 degree difference. If you need to extend the range of pulse widths the Maestro sends, you will need to adjust the “Min” and “Max” settings in the “Channel Settings” tab. Please note that sending pulse widths that correspond to positions beyond the physical limits of your servo, your servo can damage itself.

Also note that if you copy this code exactly, it will only run one time. If you want it to continually loop, you can put it inside of a begin/repeat block.

-Brandon

Sorry for the late reply. the code worked great!! thanks!!! i just need to add the begin/repeat and play with the ms but i keep forgetting my project at home lol.