連結 FLASH

2019-03-24 10:09发布

我想要按下按钮板子的灯亮起FLASH上也要出现颜 {MOD}

卡在FLASH



按下去后MSP430灯亮

可是FLASH 不会跳出颜 {MOD}



MSP430程式码

#define ledPin1 14

#define ledPin2 2

#define button1 10

#define button2 8

#define TOGGLE_LED_STATE 't'

#define Red_LED_STATE 'r'

#define Green_LED_STATE 'g'

#define msgstop 's'

#define EOL_DELIMITER "$"

int incoming = 0;

int in=-1;//定义一个变量,用于接收数据时用

int button1State = 0;         // variable for reading the pushbutton #1 status

int button2State = 0;         // variable for reading the pushbutton #2 status

boolean shouldBlinkLED = false;





// variables will change:





void setup()

{

   // initialize the LED pins as  output:

  pinMode(ledPin1, OUTPUT);     

  pinMode(ledPin2, OUTPUT);     



  // initialize the pushbutton pin as an input:

  pinMode(button1, INPUT_PULLUP);     

  pinMode(button2, INPUT_PULLUP);



    Serial.begin(9600);

    Serial.print("READY");

    Serial.print(EOL_DELIMITER);

}

void loop()

{

  if(Serial.available() == 0)

  {

   incoming = Serial.read();

                if(incoming== button1State) //如果收到的是開始代碼

                in=1; //變量in=1;

                if(incoming==button2State) //如果收到的是結束代碼

                in=0; //in=0;

  }

  if(button1State==LOW)

  { Serial.print("g"); //發送一個變化的值i

        Serial.println(EOL_DELIMITER); //發送結束字符

                 //  i++; //值i遞增1

           }

   if(button2State==LOW)

     { Serial.println("r"); //如果受收到結束代碼,發送off

        Serial.print(EOL_DELIMITER);

     }

   {

  button1State = digitalRead(button1);



  // check if the pushbutton is pressed.

  // if it is, the buttonState is HIGH:

  if (button1State == LOW) {     

    // turn LED on:   

    digitalWrite(ledPin1, HIGH);



  }

  else {

    // turn LED off:

    digitalWrite(ledPin1, LOW);

  }

  // read the state of the pushbutton value:

  button2State = digitalRead(button2);



  // check if the pushbutton is pressed.

  // if it is, the buttonState is HIGH:

  if (button2State == LOW) {     

    // turn LED on:   

    digitalWrite(ledPin2, HIGH);



  }

  else {

    // turn LED off:

    digitalWrite(ledPin2, LOW);

  }  

}

}




FLASH程式码

package

{

import flash.events.Event;

import flash.display.Sprite;

import flash.display.MovieClip;;

import flash.net.Socket;

import flash.events.IOErrorEvent;

import flash.events.ProgressEvent;

import flash.events.SecurityErrorEvent;

import flash.utils.Endian;

import flash.events.MouseEvent;



public class getshu extends MovieClip

{



         public static var ardmsg:String;







private static const TOGGLE_LED_STATE:String = "t";

private static const Red_LED_STATE:String = "r";

private static const Green_LED_STATE:String = "g";

        private static const msgstop:String = "s";

private static const EOL_DELIMITER:String = "$";







private var _socket:Socket;





private var _proxyAddress:String = "127.0.0.1";





private var _proxyPort:uint = 5333;





public function getshu()

{

addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);

}





private function onAddedToStage(event:Event):void

{

removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);





var s:Sprite = new Sprite();





//s.graphics.beginFill(0xFF0000);

//s.graphics.drawRect(280,250, 100,100);

//s.graphics.endFill();





addChild(s);





//position it

s.x = 50;

s.y = 50;





s.addEventListener(MouseEvent.CLICK, onClick);



_socket = new Socket();





_socket.addEventListener( Event.CONNECT, onConnect );





_socket.addEventListener( Event.CLOSE, onClose );





_socket.addEventListener( ProgressEvent.SOCKET_DATA, onSocketData );





_socket.addEventListener( IOErrorEvent.IO_ERROR, onIOError );





_socket.addEventListener( SecurityErrorEvent.SECURITY_ERROR, onSecurityError );





_socket.endian = Endian.LITTLE_ENDIAN;





_socket.connect(_proxyAddress, _proxyPort);

}





private function onConnect(event:Event):void

{

trace("Socket Connected");

}





private var buffer:String = "";





private function onSocketData(event:ProgressEvent):void

{

var data:String = _socket.readUTFBytes( _socket.bytesAvailable );





buffer += data;





var msg:String;

var index:int;





while((index = buffer.indexOf(EOL_DELIMITER)) > -1)

{

msg = buffer.substring(0, index);





buffer = buffer.substring(index + 1);





trace("Message Received from Arduino :" +msg);





if(msg=="r") {

graphics.beginFill(0xFF0000);

graphics.drawRect(0, 0, 100, 100);

graphics.endFill();

}

else if(msg=="g") {

graphics.beginFill(0x00FF00);

graphics.drawRect(0, 0, 100, 100);

graphics.endFill();



}

























}

ardmsg=msg;





}

          private var i:Number;

private function onClick(event:MouseEvent):void

{

trace("onClick");





if(!_socket.connected)

{

trace("You must be connected to send a command to the Arduino.");

return;

}





//下面是点击按钮时发送开始字符,再点击发送结束字符

if(i==0)

{

_socket.writeUTFBytes(Green_LED_STATE);

i=1;

}

else

{

_socket.writeUTFBytes(Red_LED_STATE);

i=0;

}

_socket.flush();

}

private function onClose(event:Event):void

{

trace("Socket Closed");

}

private function onIOError(event:IOErrorEvent):void

{

trace("IOErrorEvent : " + event.text);

}





private function onSecurityError(event:SecurityErrorEvent):void

{

trace("SecurityErrorEvent : " + event.text);

}

}

}







此帖出自小平头技术问答
0条回答

一周热门 更多>

相关问题

    相关文章