How to control multi DC motors by Max6 (Serial communication)

Hello, In order to control a DC motor, I have done a program that Arduino talking to Max6 through Serial communication. However, to control 2 DC motors, I could not do it. So, I would like to use multi DC Motors controlled by Max6. I will put my current sketch below, please anyone smart helpers modify my current sketch?

Regards,

M

const int Lpin = 9; const int Rpin = 10;

const int Lpin2 = 5; const int Rpin2 = 6;

int val = 0;

int receiveData = 0; int selectRotate = 0;

define ROTATE 0

define INVERT 1

define BRAKE 2

define ROTATE2 3

define INVERT2 4

define BRAKE2 5

void setup(){ Serial.begin(9600);

pinMode(Lpin, OUTPUT); pinMode(Rpin, OUTPUT); pinMode(Lpin2, OUTPUT); pinMode(Rpin2, OUTPUT); } void loop(){ if(Serial.available() > 0){

receiveData = Serial.read(); if(receiveData == 255){ selectRotate = ROTATE; } else if(receiveData == 256){ selectRotate = INVERT; } else if(receiveData == 257){ selectRotate = BRAKE; } else if(receiveData == 258){ selectRotate = ROTATE2; } else if(receiveData == 259){ selectRotate = INVERT2; } else if(receiveData == 260){ selectRotate = BRAKE2; } else{ switch(selectRotate){ case ROTATE: setRotateMode(); break; case INVERT: setInvertRotateMode(); break; case BRAKE: setBrakeMode(); break;

case ROTATE2: setRotateMode2(); break; case INVERT2: setInvertRotateMode2(); break; case BRAKE2: setBrakeMode2(); break; } } receiveData = 0; } }

void setRotateMode(){ digitalWrite(Lpin, LOW); digitalWrite(Rpin, LOW);

delayMicroseconds(10);

digitalWrite(Lpin, LOW); analogWrite(Rpin, receiveData); }

void setInvertRotateMode(){ digitalWrite(Lpin, LOW); digitalWrite(Rpin, LOW);

delayMicroseconds(10);

analogWrite(Lpin, receiveData); digitalWrite(Rpin, LOW); }

void setBrakeMode(){ digitalWrite(Lpin, LOW); digitalWrite(Rpin, LOW);

delayMicroseconds(10);

digitalWrite(Lpin, HIGH); digitalWrite(Rpin, HIGH); }

void setRotateMode2(){ digitalWrite(Lpin2, LOW); digitalWrite(Rpin2, LOW);

delayMicroseconds(10);

digitalWrite(Lpin2, LOW); analogWrite(Rpin2, receiveData); }

void setInvertRotateMode2(){ digitalWrite(Lpin2, LOW); digitalWrite(Rpin2, LOW);

delayMicroseconds(10);

analogWrite(Lpin2, receiveData); digitalWrite(Rpin2, LOW); }

void setBrakeMode2(){ digitalWrite(Lpin2, LOW); digitalWrite(Rpin2, LOW);

delayMicroseconds(10);

digitalWrite(Lpin2, HIGH); digitalWrite(Rpin2, HIGH); }

Please read the advice and post code in code tags, its so much easier to handle.

Max6? What is Max6? I found a GPS receiver called MAX-6....

MarkT

Thank you for a quick reply. The Max6 is a visual programming language for music, video and multi-media development. http://cycling74.com/products/max/

M