使用Arduino mega 2560的Arduino2max数字引脚通信最大化

时间:2012-04-07 18:07:24

标签: c serial-port arduino max max-msp-jitter

我正在努力将Arduino Mega 2560连接到max msp,我已经调整了Arduino2max arduino代码和最大补丁。

我已经调整了最大补丁,并且成功地将所有16个模拟输入从arduino转换为max,但是无法将数字引脚从13号转换为最大msp。我想知道是否有人对此有任何成功?

非常感谢任何帮助和评论!

非常感谢

这里是改编自Arduino2max v.5的arduino代码,可在此处找到http://www.arduino.cc/playground/Interfacing/MaxMSP

int x = 0;              
int ledpin = 13;

void setup ()
{
// 115200 is the default Arduino Bluetooth speed
Serial.begin(115200);
///startup blink
digitalWrite(13,HIGH);              
delay(600);
digitalWrite(13,LOW);
pinMode(13,INPUT);
}



void loop()
{ 
// Check serial buffer for characters
if (Serial.available() > 0){  
if (1){     //Serial.read() == 'r') { // If an 'r' is received then read the pins 
// Read and send analog pins 0-15
for (int pin= 0; pin<=15; pin++)
{ 
 x = analogRead(pin);
 sendValue (x);
}

// Read and send digital pins 2-53
for (int pin= 2; pin<=53; pin++)

{         
 x = digitalRead(pin);
 sendValue (x);
}

 // Send a carriage return to mark end of pin data.
    Serial.println(); 
 // add a delay to prevent crashing/overloading of the serial port
delay (5);                        
 }
}
}
// function to send the pin value followed by a "space".
void sendValue (int x){ 
 Serial.print(x);
 Serial.print(32, BYTE);
 }

再次感谢!

1 个答案:

答案 0 :(得分:0)

我建议您使用OSC协议在Arduino Mega和Max之间进行通信。 我使用库ardosc。没有关于它的文档,但它并不是很难使用它,它是一个很好的库。

如果你不能使用它,请不要犹豫,问我一些解释

相关问题