multiple values over serial (messenger)

Hi. sorry for the question on whats a rather basic subject but I've been working on it for three days and still can't wrap my head round it.

I want to send mouse x/y coordinates from processing to my arduino to light two LEDs (one for x, one for y). So far I've worked out that I probably want to use messenger for this but for the life of me I can't sort it out after reading everything I can find on the subject.

My only problem is getting the serial data turned into a 'real' numberin the arduino.

Could someone please explain how I would get the processing output "123 456[cr]" split and stored on the arduino so that 123 was in one int variable and 456 in another

thanks,
Kieran

Have you thought of searching the forum?
This topic only comes up about once a week.

yes, multiple times and the references and everything that came in the messenger .zip and about fifteen pages worth of google.

I'm rather surprised it's hasn't already got a learning article

So what have you written so far?
Maybe you're nearly there, and just need a nudge in the right direction.

int xPin = 9;      // the pin that the LED is attached to
int yPin = 10;
int xVal = 0;
int yVal = 0;

Messenger message = Messenger();

void messageCompleted()
{
  while ( message.available() )
  {
    xVal = message.readInt();
    yVal = message.readInt();
  }
}
    

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  // initialize the ledPin as an output:
  pinMode(xPin, OUTPUT);
  pinMode(yPin, OUTPUT);
  
}

void loop() 
{
  while ( Serial.available( ) ) message.process(Serial.read( ) );
  messageCompleted();
  xVal = xVal / 2;
  yVal = yVal / 2;
  analogWrite(xPin, xVal);
  analogWrite(yPin, yVal);
  
}

It's a tad messy since ATM i'm just frankensteining code together from different examples I can find in an effort to work it out

I would be very interested too, I can't find anything of that topic in the forum.
would you be so kind and give me the right keyword so that I can search for it?
thank you :slight_smile: