Having issues sending IR (Sharp 2Y0A21) data to Max Msp

stevepk123's icon

Hello, I'm Having issues sending IR (Sharp 2Y0A21) data to Max MSP. i have scaled the data to cm in Arduino but I am unable to receive any data into Max. any help would be great.

Arduino code:

int x;
double dist;

void setup ()

{
Serial.begin(9600);
}

void loop ()
{

x = analogRead(0);
dist = (pow((3027.4/x), 1.2134));
Serial.println(dist);
// Serial.write(x);
delay(200);
Serial.write((int)dist);

}

Max patch is using (see pic)

brendan mccloskey's icon

Delete the serial.println line and move the delay bit to the last line. Change serial.write ((int)dist) to serial.write (dist).

stevepk123's icon

Hey, thanks I'v changed it to the following now, however upon compiling the error message 'call of overload 'write.(double&)'is ambiguous'

int x;
double dist;

void setup ()

{
Serial.begin(9600);
}

void loop ()
{

x = analogRead(0);
dist = (pow((3027.4/x), 1.2134));
Serial.write(dist);
delay(200);
}

Screen-shot-2014-04-26-at-14.31.20.png
png
brendan mccloskey's icon

Oops
Maybe put the ((int)dist) thing back then. I forgot you were using double.

stevepk123's icon

That works within Arduino and does the conversion to cm however I am having issues receiving this data within Max-MSP.

Attached is a screen-shot of the Max-patch although the route object has now been changed to match nn nn etc as I am using Steven Miller's Arduino code to prevent the reversing/inverting of the LDR's what works great. The overall plan is to incorporate 3/4 Sharp sensors in with the 12 LDR sensors to map height, thus changing velocity/pitch etc.

Thanks again for your help it's much appreciated.

Screen-shot-2014-04-27-at-10.19.50.png
png
brendan mccloskey's icon

You really need to just use Steven's example patch and code. Random hacking like this will mean continuing questions and problems. . .

Posting just images is also no help whatsoever

brendan mccloskey's icon

Steven's code is designed to work with the example patch he included. It's clearly annotated so perhaps you need to explore and interrogate both elements so that you are able to successfully adapt it for your specific needs.
It would be trivial for someone to post a complete system that does exactly what you need. But you would learn nothing.

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

In case you missed Steven's examples:

Brendan