2013年9月13日 星期五

Arduino連接Flash

首先我們要先把程式燒進Arduino裡頭

而網路找的程式有部份要修改

原本的程式compile會卡在printByte這裡 把這都改成Serial.print就可以compile過燒進arduino裡頭

所以正常的pde程式為
==============================================
int activeLED ;
int switchState = 0;
int lastSwitchState = 0;
int switchPin = 13;
void setup()
{
  Serial.begin(19200);
  pinMode(switchPin, INPUT);
  for (int i = 2; i <= 9; i++) {
    pinMode(i, OUTPUT);
  }
}
void loop ()
{
  switchState = digitalRead(switchPin);
  if (switchState != lastSwitchState) {
    if (switchState == 1){
  sendStringToFlash("switchOn");
    } else if (switchState == 0){
  sendStringToFlash("switchOff");
    }
  }
  lastSwitchState = switchState;
  if(Serial.available() > 0) {
    activeLED = Serial.read();
  }   
  if(activeLED >= 50 && activeLED <= 57) {
    int outputPort = activeLED - 48;
    Serial.print("LED port ");
    Serial.println(outputPort);
    if(outputPort >= 2 && outputPort <= 9) {
  for (int i = 2; i <= 10; i++) {
    digitalWrite(i,LOW);
  }
  digitalWrite(outputPort, HIGH);
    }
    activeLED = 0;
  } else if (activeLED) {
    Serial.print("Invalid LED port ");
    Serial.println(activeLED,BYTE);
  }
  delay(50);
}
void sendStringToFlash (char *s)
{
  while (*s) {
    Serial.print(*s ++);
  }
  Serial.print(0);
}

===============================================

再來要開啟serproxy的程式

連接flash中 這個程式都要一直開啟

有正常就會出現wait client..

接下來連接成功arduino後

要記得看你的COM是多少

在控制台連接埠可以看

我們是COM3的話Flash裡頭的程式var port:Number = 5333;後面就為5333

記得import的.as檔也要修改成5333

再接好你的arduino的LED後

發佈Flash  就可以由Flash來控制你的LED亮燈在哪幾顆 // comment http://code.google.com/p/as3glue/downloads/list 可以改用as3glue 比較沒問題

沒有留言: