Need a way to exclude sensor readings after a peak is reached
I have a problem that I suspect is pretty simple question but I can't figure it out!
I have a sensor attached to a select object, that flips a toggle when the sensor reads over a certain number, so each time a sensor is pressed the toggle turns from on to off, or off to on. Easy.
However, as you might imagine, if the sensor reads above the threshold it the toggle turns on and off rapidly, as it's sensing multiple above-threshold events over time.
I need a way to receive one peak event and exclude others for a certain number of milliseconds - like 200 or something - to prevent this rapid on/off behaviour. I guess that's delay? I'm not in any way a Max expert so I think I might be missing an object here that I just don't know about, or an attribute I keep missing. Thanks for any ideas!
You're looking for *hysteresis*, which I feel can best be achieved with two independent thresholds:
One that sets the "above" threshold, and one for "below", so that the signal has to travel below the lower threshold in order to activate the top one.
You're not missing an "object" per se, you're probably looking to build a little subpatch that handles this, like 5-10 objects, and then you can reuse this when you need it.
The patch itself I'll leave as an exercise for the reader, I guess.
The solution might be even simpler than that, merely filtering out repeated 1 or 0 (on or off) messages with the change object.
ah you beat me to it, yes use change after the >= object which will allow no more new triggers until the sensor drops below your threshold. If you still have problems then you might think about implementing hysteresis.
this is a very simple implementation:
Thanks so much Leafcutter, that's such a good example - I was totally missing the trigger object between the select and change. (BTW, Leafcutter John? If so your NIME performance this year was great!)
I think that maybe the change object isn't what I need though ... I tried it before and I'm not sure it's what I'm trying to do as I simply have to switch the toggle every time the input is above 400, and not change it if the input falls below again. (As in, each input > 400 flips the toggle from whatever position it happens to be in, and it stays in that position until another threshold event). I can't send a bang to the change object, instead only a trigger, which needs a specific number. Every time I hook up more than 1 trigger message to the change object there's a stack overflow so I'm clearly either doing something wrong or taking entirely the wrong approach.
I think this has slid into a control issue, sorry if this is super rudimentary!
Is this change to Leafcutter's patch what you are looking for?
`
ah I think I see what's going on; you're sending out a lot of bangs, and change obviously won't work in that situation - am I wrong?
This works using a [delay] object:
You're all so great, thanks for the suggestions.
Wetterberg - Yes, exactly. I have to send a specific number to the change object, I can't just bang the toggle. Is it possible to do this without a change object?
Also, I forgot to follow this up - Simon, that was absolutely the perfect edit and solved my problem.
Thanks so much everybody, I really appreciate that support for these really simple problems! :)