Simple Question – Press and Hold/ Click and Hold

Apr 23, 2013 at 5:03am

Simple Question – Press and Hold/ Click and Hold

A quick question.

How to I get Max/Msp to register a bang that lasts for 2 seconds +/- 0.5?

Similarly, how would I get Max/Msp to register a bang lasting EXACTLY 2 seconds.

Many thanks

#67888
Apr 23, 2013 at 5:28am

Hi
Try the [clocker] object.

#244092
Apr 23, 2013 at 6:52am

What do you mean by “a bang that lasts for 2 seconds?” Bangs have no length.

#244093
Apr 23, 2013 at 1:49pm

I have serial connected (physical) button which, when pressed for 2 seconds lights should light up an LED.

Good point re: Bangs Chris.

Allow me to explain.

At the moment the button, when pressed sends a contant string of “a” through serial to Max. I suppose I could count how many “a’s” are sent but this feels a little too hacky.

I have three modes that I want to toggle between

1) On/off
2) Mode 1
2) Mode 2

When I press the button ‘normally’ and repeatedly it should simply toggle between modes 2 & 3.
However, I want mode 1 only be initiated by a long 2 second press.

Noob_Meister, I tired the Clocker object but all that seems to do is start counting when it receives a bang. Any tips?

#244094
Apr 23, 2013 at 2:01pm

With clocker:

Send a bang when the button is pressed down, then another when the button is un-pressed/stops being pressed down. Use clocker to get the time spent in between. (one bang starts, the other stops). If you’re doing it with serial, this is easy – just send ‘a’ for button-down, and ‘b’ for button-up. Assuming you’re using an arduino for your device, look into the bounce (http://playground.arduino.cc/code/bounce) library – it has some nice edge-detection functions specifically for this kind of purpose.

Alternatively, use [cpuclock]. Compare the most recent value of the output of cpuclock to the previous value of cpuclock, and use that value for your logic. If it’s above some amount of time, ignore it.

#244095
Apr 23, 2013 at 2:08pm

Alternate strategy (and this is a fairly standard technique):

When button gets a mouse down, trigger a [del 2000] object. If you get a mouse up (before the 2 sec are up), send a ‘stop’ message to the [del] object and toggle between modes two and three. If the [del] object fires, handle mode one (and ignore the next mouse up).

If you still want to handle mouse tracking (ie, you’re handling a mouse up outside the button differently from a mouse up inside the button), then proceed as above, but use the delay to trigger a gate to handle the two different options. You will need to set that gate to a “default” position on the initial mouse down.

#244096
Apr 24, 2013 at 1:21am

Thanks for your help. I ended up using a combination of Clocker and Past.

– Pasted Max Patch, click to expand. –
#244097
Apr 24, 2013 at 9:15am

If you like to handle mouse tracking ( you’re handling a mouse up outside the button differently from a mouse up inside the button), then check the post above. You will have to set that gate to a “default” position on the initial mouse down. Armbånd

#244098

You must be logged in to reply to this topic.