Max MSP serial communication

Thanks for the link, I was checking out maxuino but I was curious how to do this without it.

The thing I don't understand is ...

  1. How to properly send information to the arduino, and how to even tell if it is receiving any information from max.

  2. What to write codewise for the arduino in order to distribute the information I am sending from max to the arduino. I am trying to send two numbers to the code, one to control the motor's speed and another to indicate HIGH or LOWin order to switch the direction of the motor.

What kind of code do you write to tell the arduino where to put the numbers you are sending it?

analog write controls the motor's speed so I was trying to write the code so that the first set of numbers I send from max are to control the speed.

I can type in a number from 0 to 255 and upload it to change the speed but I want to use max so I can vary the speed from the computer. My only idea was to define a variable called "thespeed" based off of the information coming from the serial port. But I don't know if the arduino is receiving any numbers from max let alone knowing what to do with them.

analogWrite(enablePin,thespeed);

I found information on parsing the numbers you send in a string and I tried to use that information in my code to define the numbers the arduino is recieving but I don't know if it is close to what is the proper thing to do, I am just guessing . I did this ....

while (Serial.available() >0) {

int thespeed = Serial.parseInt();
int thedirection = Serial.parseInt();

if (Serial.read() == '\n') {

thespeed = 255 - constrain(thespeed, 0, 255);
thedirection = 255 - constrain(thedirection, 0, 255);

analogWrite(enablePin,thespeed);

}

Does this look close to right? I am looking into maxuino but if I could do this without it I'd really prefer to, just so I have more of a chance to understand how the arduino itself works.