Switches


begin
  button_a if sequence_a endif
repeat
 
# These subroutines each return 1 if the corresponding
# button is pressed, and return 0 otherwise.
# Currently button_a is assigned to channel 0, 
# button_b is assigned to channel 1, and
# button_c is assigned to channel 2.
# These channels must be configured as Inputs in the
# Channel Settings tab.
sub button_a
  1 get_position 500 less_than
  return
# These subroutines each perform an arbitrary sequence
# of servo movements.  You should change these to fit
# your application.
# Sequence 0
sub sequence_a
sub button_b
2 get_position 500 greater_than
if sequence_b
else 6000 0 servo
endif
 
sub sequence_b
  2000 6000 0 0 0 0 0 
  0 0 0 0 0 frame_0_2..11 # Frame 4
  2500 8000 frame_0 # Frame 0
  2300 3968 frame_0 # Frame 1
  4000 5435 frame_0 # Frame 2
  2000 6000 frame_0 # Frame 3
return

sub frame_0_2..11
  11 servo
  10 servo
  9 servo
  8 servo
  7 servo
  6 servo
  5 servo
  4 servo
  3 servo
  2 servo
  0 servo
  delay
  return

sub frame_0
  0 servo
  delay
  return

Hi, here are my demands for two pushbuttons:
1st button has to start the programmed sequence on one channel.

2.nd button pushed down momentarily should abbort the programmed sequence, set servo to neutral position, and reset the sequence to the beginning without starting it new, unless i will push 1st button again.

AND :exclamation:

2nd button also needs to set a servo as long as I have it pushed DOWN.

Button 1 works fine,
but i can`t figure out how to implement the second switch to overide the running sequence.

On the Top is my last try to enter the servo positioning function by a long push of the button.
Thx for your help!

Hello.

If you want the script to stop or pause if you press a button mid-sequence, you will need to check if the button is pressed between each command and return from that subroutine if it is. The problem that you might run into with this is that you are using delays, and the script is not checking the button during these delays, so the button presses will be ignored if they are done during a delay.

There are a couple of things you could try to get around this, such as using the GET_MOVING_STATE command, either with the channel your servo is connected to, or a dummy channel. You might also be able to break your delays up into shorter delays and check the button in between them (e.g. instead of delaying for one second, you can delay for an eighth of a second eight times, checking the button in between. This could throw the timing off slightly since you are adding commands to the delay time, but it could be fine if your application is not very sensitive to timing.

I suggest getting one part of the script working as intended before moving on to the next, but as far as having your second button set a servo to a target while it is pushed down, you might consider using the subroutines from the “Using a button or switch to control servos” example script found in the Example Scripts section of the Maestro controller’s user’s guide. The subroutines in that example show how to do button debouncing. The wait_for_button_open_10ms subroutine can be used to determine when the button is released, so you could use it to set up a script that sends the servos to particular positions and waits for the button to be released before moving on.

-Brandon

Thx Brandon!, I’ll keep on trying!