Distance Sensor, Arduino, Max and routing a range of input to a tone

ptm1's icon

Can anyone give me some suggestions on how to do the following:

I'm using an ultrasonic distance sensor hooked up through Arduino. I want to capture the distance data in Max and route a range to specific tones.

for example
1)if something is 600-800cm play a 90hz sine wave
2)if something is 300-600cm play a 900hz sine wave
3)if something is 0-300cm play a 60hz sine wave

I have the cycle~ and frequency part down..i just need to know the best way to route the ranges

I've tried using split~ and routing ranges into 3 different cycle~ and audio out objects but when 1) moves past the threshold and plays 2) the 1)just gets stuck at the peak and continues to play. I'd like the transition b/w ranges to be smooth

brendan mccloskey's icon
Max Patch
Copy patch and select New From Clipboard in Max.

using three separate [cycle~] objects is the problem; can you just use one, and use the ranges to trigger discrete frequency values, like this:

if you need something with a little more, um, finesse, then say the word
Brendan

brendan mccloskey's icon
Max Patch
Copy patch and select New From Clipboard in Max.

actually, i like this version better; smooth transitions between frequencies; no doubt someone will suggest something a little more elegant:

ptm1's icon

I'm not sure what to do with this. How do I open this patcher in Max? I'm just learning MaxMSP btw.

ptm1's icon

nevermind...I just figured it out. Open from clipboard. Wow I had no idea you could do that. Thanks for doing that...i'll hook it up and get back to you

brendan mccloskey's icon

well, if you're programming the Arduino and piping data to MaxMSP, that's pretty hardcore dood; let me know how you get on

Brendan

Tj Shredder's icon

I'd stick to one cycle~ and splits and smooth the frequency transition, another option to do smooth switching is a matrix~...

Max Patch
Copy patch and select New From Clipboard in Max.

Stefan

brendan mccloskey's icon

@stefan, I was right

"no doubt someone will suggest something a little more elegant"

[matrix~], nice

Brendan

ptm1's icon

THanks for the help guys..Brendan your second code was working pretty smoothly. Stephan yours def gave it a clean ramp. This is for a school project ...i'll try to post a vid for you guys to see when i'm done. Again, this was extremely helpful!!

hzd's icon

Hi there.

How did you get the range into Max?

I strugeling with this.