2167|0

1

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

連結 FLASH [复制链接]

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

卡在FLASH



按下去后MSP430灯亮

可是FLASH 不会跳出颜色



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);

}

}

}







 
点赞 关注

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表