Play/Stop sound with sensor Help

TRICAUD Pascal's icon

Hello,

For an installation, I would like to control the playback of 2 sounds depending to an ultrasonic sensor. When the sensor value is below a certain value a sound play and in the other case an other sound.

I already plug my arduino to Max and I'm able to get the values of the sensor. I send this values to an if condition ( if $f1 < 214 then 1), plug to a toggle, plug to a 1 plug to the playlist. The problem is that when the value of the sensor is below 214 it keep sending play messages and my audio file make a tiny loop...

Have you got an idea to send only 1 play message when the value goes under 214 ? And stop it when it's above the value?

Please I'm really need for help, this is an important project and I don't have much time left...

Thank you anyway and good day

Gregory Taylor's icon

Have you looked at the change object?

Jan M's icon

That's not directly related to your question, but to share some experiences: ultrasonic distance sensors (at least the cheap ones) are quite tricky to work with. In my experience the tend to change their behavior a lot with the conditions (space, humidity of the air... and they don't work well when people where cloths like woolen sweaters/cardigans (those material absorb the sound). And they tend to produce very noisy data. If you don't need to cover lager distances (not more than about 1 1/2 meters or about 4 feet) you might want to try infrared distance sensors as well. And or apply some smoothing to avoid accidential triggering the sounds....

TRICAUD Pascal's icon

Hi,

Thank's a lot for responding me so fast ! However, it was my first post so I had to wait the check of my post which takes several hours and meantime I found out the solution...
I manage my problem with the change object with maintain my value and it work fine ! Thank's anyway Gregory, that was exactly that !
And yeah I figure it out with another trial with ultrasonic sensors, but for this one, they're placed beyond a canvas so the value is quite stable, and not so much diffraction !

For now, the next step of my project is to send a color variation for a LED stripe (when we touche the canvas the color must change slowly), I'm on QLC+ but I don't now where to go, should i use MIDI? or OSC? (I'm quite confuse, all the tutorials are not very specifics...)

I guess I'lle have to make another post...

Thank's again guys !