Slide Pot and switch to control one servo

Hi,

I’m using a mini maestro 6 and a slide pot to control a servo. This works great using your example script.
Is it possible to put a switch on INPUT 2 and have that bypass the pot and make the servo move to full extent and then back to start once the button is released?

Thanks,

Jon

Hello.

It sounds like what you are describing should be possible with some modification to one of the “Using an analog input to control servos” example scripts.

For example, if you want the servo to ignore the potentiometer and move to a specific location when the button is pressed (and return control to the potentiometer when it is released), you could use an if/else statement to handle that. That might look something like this:

begin
  2 get_position     #get the value of the input on channel 2
  500 less_than if   #if it is less than 500 (i.e. the button is pushed)
  
    4000 0 servo      #move the servo on channel 0 to 1000us
  
  else                        #if the button is not pressed
    
      #add analog input control code here

  endif
repeat

Brandon

Hi Brandon,

Thanks for your help,
Unfortaunately I still cant get it work, something silly I’m doing I’m sure!

When I attach the button the slide pot doesnt work and when I attach the slide pot the button doesnt work.

I’ve attached a pull up resistor on channel 0 for the switch and the variable pot on channel 1

My code is:


begin

  0 get_position     #get the value of the input on channel 0

  500 less_than if   #if it is less than 500 (i.e. the button is pushed)

    4000 5 servo      #move the servo on channel 5 to 1000us

  
  else                        #if the button is not pressed

    
# Sets servo 5 to a position based on an analog input.

begin

  1 get_position             # get the value of the pot, 0-1023
  4 times       4000 plus # scale it to 4000-8092, approximately 1-2 ms
  5 servo                       # set servo 5 based to the value

repeat

  endif

repeat

Would appeciate any help thanks,

Jon

Hello.

You should remove the begin and repeat commands between else and endif. This begin/repeat block will cause an infinite loop and the code will never return to checking the button.

If that doesn’t solve the problem, could you verify that your button and slide pot are working as expected by monitoring those channels in the “Status” tab as you use them? Posting a copy of your settings file might help as well. You can save your settings file from the “File” drop-down menu of the Maestro Control Center while the controller is connected.

Brandon

That worked perfectly.

Thanks again for your help,

Jon

1 Like