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.
Try the [clocker] object.
What do you mean by "a bang that lasts for 2 seconds?" Bangs have no length.
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
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?
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.
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.
Thanks for your help. I ended up using a combination of Clocker and Past.
----------begin_max5_patcher---------- 689.3ocyV00aaBCE8YxuBDOsIkEggjTXuseGSSUF3FhScrQ1lzzU0+6y9ZHk 1DRSqZ65Kf7W264d74X66mDDUH2C5nveF96vff6mDDfc45HnqcPzV59RNUiS KR.2JK1DM0OjA1avtanZSemxVCGLl6Z.efiJnh5nv+zM7JovHnawAi9khQ48 KTztkIrKEyDoqyFpobMSTesBJM9.RhSVLKdZ3hzD2uTrQBYV7gbvpvnaQ5OH ICBuGZOI9N3nY+EgCIcVrq2GlLw8Y5ExIEsFiTbgk+qtHWFik2gumpHSxFoH eCUSob6VPXNZKtBVwDP3NJuE9l96gFYnrPCpcP+T41wKksBb9I87qptv01g+ WR.TzVTvggDyEyVjEW4Hn4I3OBYN1ZD5JkbZ5J98SSrEzZZMbDKpAicWLNdT 0xq1njbNVIF0PySQVwqjH4iPJW8gaTFSZsRpps7RiB1wjsZ9cg1Z.X6fpPln o07URfk4IQu4bTAV9+MAVIGnpOI0UmKKOd1B6wv4mScsXwGt5Zitk0mDVsPZ QJmUdyvrbF9Xilppacxyt6C82ocX7BopBTC2Du7SxyHCtthPxPyX1.hZEiCG 1LVC7FKVzy1niNlHu5fM0NI6RLf5Z6Z6j0wuaWCL5AXFYymh7JO1a3HKwK4S QtK6zpq7Wg3J4MItF4cOkbY4Mv39sUbI07dxJYyQa17kYdq24dUP5alUvngG 29rGGhHx0+SoJsrUU1WycoN7QLUAZCSPML6qjdbNtWlMXRqYUUfXnHthoc5Z rfN8d1kBmmkpSiG2in9jvi6t1uR7i6z4uR3I+BfS5Kflac4pQxDlq8dh4GOv JNs9IdhwJAugf1zrCT5Nbfn2dJwFIdsvxoXSlv2DiXj6EM8yGAVDUYszFqet U4OFXe1xnIt77vj+AjqblzA -----------end_max5_patcher-----------