Preselect Servos with a Rotary Switch [micro master]

Hello there

I have a coding problem on my 6channel micro maestro servo controller.

There are 4 Servos, 1 Potentiometer and 1 rotary Switch, the Switch have different Resistors
and is connected as analog input, i get 4 Values from this switch to the controller
(~179, ~414, ~709, ~1023).

With this 4 Values from the Switch i want to preselect one from the 4 Servos.
With the Potentiometer i want to move the servo (but only the preselected from the Switch)

Any suggestions how to program this?

Here is my code (doesnt work, i know :unamused:)

Thanks for you help!

begin
5 get_position #this is the rotary switch
 dup 200 less_than
 if
 goto num1
 else
 dup 500 less_than
 goto num2
  if
  dup 800 less_than
  goto num3
  else
  goto num4
  endif
 endif
num1:
poti
3 servo
num2:
poti
2 servo
num3:
poti
1 servo
num4:
poti
0 servo
repeat

# read potentiometer value and calculate servo position (1-2ms)
sub poti
4 get_position
4 times 3800 plus
return

Hello, HeloX.

Labels (e.g. “num3:”) dont affect control flow except when a goto statment is executed. The way your code is written right now, if the Maestro executes “goto num2” then the next thing it does will be to execute all the code between “num2” and “repeat” before it goes back to the top of the loop.

You can fix this by adding 3 more goto statements. If there are more problems with your code, then I recommend you try using the “Step Script” button of the Maestro Control Center to debug it.

–David

Hi David,

thanks for your help. I didn´t recognize the Step script button :blush: , thats a very useful button, now i can see whats happenes!

Normally i work with PLC´s (siemens S7), these are different to programm.

I will change the code and try it again.

Greetings,
Christoph

success :smiley:

the code is not that perfect but it works… hehe

begin
start:
 5 get_position
 50 delay
 dup 200 less_than
  if
  goto num0
  else
  dup 500 less_than
   if
   goto num1
   else
   dup 800 less_than
    if
    goto num2
    else
    goto num3
    endif
   endif
  endif

num1:
poti
1 servo
drop
goto start

num2:
poti
2 servo
drop
goto start

num3:
poti
0 servo
drop
goto start

num0:
poti
3 servo       
drop
repeat

sub poti
4 get_position
4 times 3900 plus
return

David, thanks again for your hint :slight_smile:

Greetings,
Christoph