Have each motion trigger progress to next sequence

I have a Halloween prop that will be triggered by a motion sensor. In order to add variety, I’d like to program a few different sequences, and have the Pololu play the next sequence in the lineup each time it is triggered.

Something like:

On motion sense, play sequence 1
On next motion sense, play sequence 2
On next motion sense, play sequence 3
On next motion sense, start over again at 1

Is this possible?

I think I read that selecting a random sequence is not possible, but that would be even better if it is.

Thanks!

Hello.

To avoid potential confusion, could you confirm that you are asking about using one of our Maestro servo controllers? Also, could you clarify what kind of motion sensor you’re using?

Brandon

Sorry, yes. A Mini Maestro 12.

I am using a 5V Arduino PIR. It is working fine with one sequence in the program.

From your description, it sounds like you might have already set up some sequences in the “Sequence” tab of the Maestro Control Center. If that’s the case it’s probably easiest to start by deleting any existing script you have in the “Script” tab, then clicking the “Copy all Sequences to Script” button in the “Sequence” tab. Doing this will set up each of your sequences in its own subroutine, so then you just need to add the logic for when to call them.

The code for having the sensor input trigger one of the sequences in a random-feeling way is probably a little simpler than having them trigger progressively, and it sounds like you would prefer that anyway. To accomplish this, you can have your main BEGIN/REPEAT loop cycle through checking the sensor input once for each of your sequences. This way, the sequence that plays will depend on which part of the script was being executed when the sensor happen to trigger, which isn’t actually random, but will feel that way in practice. The code you would have to add to your script to do that would look something like this:

begin

  read_sensor if  #if the sensor is triggered
    sequence_0    #play sequence_0
  endif

  read_sensor if  #if the sensor is triggered
    sequence_1    #play sequence_1
  endif

  read_sensor if  #if the sensor is triggered
    sequence_2    #play sequence_2
  endif

repeat


sub read_sensor  #subroutine to read the input on channel 0 and return 1 if it is less than 512 and 0 if it is not
  0 get_position 512 less_than 
return


### Sequence subroutines: ###

Please note that the way this sample code is written, if the signal is still low when a sequence finishes, the next sequence will play in order.

If you try writing your script (or decide you would rather have it play the sequences in order) and have problems getting it to work, you can post a copy of your Maestro settings file here, and I would be glad to take a look. You can save a copy of your Maestro settings file from the “File” drop-down menu of the Maestro Control Center while the controller is connected.

Brandon

1 Like

Thanks! This worked!

I did have to change my read_sensor subroutine to “11 get_position 150 greater-than” for my particular PIR, but otherwise it works perfectly!

1 Like