|
3#
樓主 |
發表於 2012-10-18 10:12:37
|
只看該作者
本帖最後由 frty5566 於 2012-10-18 11:05 編輯
已經可以相容了 謝謝
那請問一下 我想要把藍芽傳送數據到 max5.0 的話
我是把MultiColorLamp 這個程式 與SimpleMessageSystem 合在一起
然後燈可以反應 但是max5.0 卻沒反應 是max的問題 還是aeduino的問題
#include <SimpleMessageSystem.h>
#include <MeetAndroid.h>
MeetAndroid meetAndroid;
int redLed = 9;
int greenLed = 10;
int blueLed = 11;
void setup()
{
Serial.begin(57600);
meetAndroid.registerFunction(red, 'r');
meetAndroid.registerFunction(green, 'g');
meetAndroid.registerFunction(blue, 'b');
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(blueLed, OUTPUT);
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, HIGH);
digitalWrite(blueLed, HIGH);
}
void loop()
{
meetAndroid.receive();
if (messageBuild() > 0) {
switch (messageGetChar()) {
case 'r':
readpins();
break;
case 'w':
writepin();
}
}
}
void red(byte flag, byte numOfValues)
{
analogWrite(redLed, meetAndroid.getInt());
}
void green(byte flag, byte numOfValues)
{
analogWrite(greenLed, meetAndroid.getInt());
}
void blue(byte flag, byte numOfValues)
{
analogWrite(blueLed, meetAndroid.getInt());
}
void readpins(){
switch (messageGetChar()) {
case 'd':
messageSendChar('d');
for (char i=2;i<14;i++) {
messageSendInt(digitalRead(i));
}
messageEnd();
break;
case 'a':
messageSendChar('a');
for (char i=0;i<6;i++) {
messageSendInt(analogRead(i));
}
messageEnd();
}
}
void writepin() {
int pin;
int state;
switch (messageGetChar()) {
case 'a' :
pin = messageGetInt();
state = messageGetInt();
pinMode(pin, OUTPUT);
analogWrite(pin, state);
break;
case 'd' :
pin = messageGetInt();
state = messageGetInt();
pinMode(pin,OUTPUT);
digitalWrite(pin,state);
}
}
這是max5.0的圖
|
|