First-time user: Need urgent help for use with arduino and video

r m's icon

Hello everyone,

I am a visual arts student, and I would need some help with using Max MSP in conjunction with Arduino. I am developing my final project and I am creating an an interactive piece with video wherein a ping distance sensor causes the switch from one video clip to the next in response to the distance values of the ping detector (for this, i would have to associate specific distance ranges of values of the ping sensor with a corresponding video clip). My Max MSP can read the data from Arduino (that would be data from a ping sensor that measures distance), but i want it to play a particular video clip according to the distance measured by the ping sensor
When there is no data measured, a continuous video loop would play, such that only when an obstacle is detected at a specific distance does Max MSP play a particular video (I want to associate different distance ranges to different video clips).
i have never done any computer programming before, so all of this is very new.
I have figured out how to play videos on Max, but i do not know how to associate arduino output to the videos so that when a certain range of distance values is reached, a particular video plays.
here is a screenshot of my patch so far:

so, i would need help with 3 things:
1. making the video clips save every time i open max (the video clips that i read with max do not play again when i close max and reopen it; i would like max to remember which videos i want to be played)

2. associating the input of arduino to my video clips such that a certain output from arduino causes one video to play, and another output causes another video to play, etc. when the detector detects nothing in range (3 meters is max) then a video loop keeps playing on and on.

3. my ping sensor is the following:
i realised (too late) that it sends a digital signal, but i need my data to be serial so that i actually get different numerical values for different distances so that i can associate the playing of a video to a particular distance range. I know that there must be a way to convert the digital 1s and 0s to get distance values. i would need help with that.

also, the max patch that i have used to associate arduino to max/msp is: Arduino2Max (Version .6) November 2012
Here is the link:

I would appreciate any help i can get. thanks.

Nat's icon

1. Check the loadbang object.

2. Check the split object

3. Serial data is alway "digital" so I'm not sure I understand the problem well. Usually on arduino a sensor will output values between 0 and 1024 depending on calibration, is that the case for your sensor ?

hz37's icon

That's an ultrasound range sensor you're using. It is described here:

What you can do is put the measurement in the required unit:

int inches = microsecondsToInches(duration);
int cm = microsecondsToCentimeters(duration);

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

Then put that value onto the Arduino serial bus. In Max there are several ways you can switch video based on an input number. For instance, you could say you get measurements between 0 and 64 inches and you want to play a different video for every 8 inch. A [gate] will let you do just that. Imagine that the red number is the reading from the serial port and the green LEDs are bang messages you send to play video:

Good luck!

r m's icon

Thanks for advice. I managed to make a working patch with the ping sensor. The only problem is that i am using 13 videos, so MAX/MSP crashes. I heard that "loadbang" could fix this program so that videos are only played when triggered. I am not sure about how to use this function however. I have attached my patch to this message. basically, i need to make it so that only one video cycles at a time so that the program doesn't crash. Please help if you can. thanks

finalpatch.maxpat
Max Patch
finalpatch1.maxpat
Max Patch
hz37's icon

The Max 7 playlist does this wonderfully. Just loop your videos and send the appropriate number to the playlist as an index of which video to play [1..n]. I'll attach a screenshot of how that looks. Instead of the message boxes you will of course compute the index from your Arduino output.

Screen-Shot-2015-04-14-at-00.05.50.png
png
r m's icon

Looks great, but do you think i can achieve smooth playback with the patch that i already have (attachment in previous message)? I only have 2 days left to work on this, and i am not at all familiar wit MAX 7.

hz37's icon

But you do have access to Max 7? Your patch will open in Max 7 just fine, and the amount of time to fix your crashes might very well be greater than the amount of time it takes to adjust to Max 7 and learn about playlists. Just think about that. Good luck!

Christian Otte's icon

Hey hey! Did you manage to figure this out? I'm in pretty much the same position as you and am not that big an expert on Max, so if I could see your final patch it would be very helpful :)