So I'm trying to use flash to send small "commands" to my arduino over usb serial I have my arduino code set up but i can't seem to get any response once I press my button in flash. I'm using serproxy and the flash connects but after that I'm stuck.
here is my arduino code.
const int ledPin = 13;
int incomingByte;
int m = 0;
int ledState = LOW;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
if (incomingByte == '1') {
m = 1;
}
if (incomingByte == '2') {
m = 2;
}
if (incomingByte == '3') {
m = 3;
}
if (incomingByte == '4') {
m = 0;
}
if (incomingByte == 'p') {
Serial.println(m);
}
}
switch (m) {
case 1:
digitalWrite(ledPin, HIGH);
delay(100);
break;
case 2:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
digitalWrite(ledPin, ledState);
delay(100);
break;
case 3:
digitalWrite(ledPin, HIGH);
delay(10);
digitalWrite(ledPin, LOW);
delay(100);
break;
default:
digitalWrite(ledPin, LOW);
break;
}
}
And my Action Script 3 code.
import flash.net.Socket;
var mySocket = new Socket
mySocket.connect("127.0.0.1", 5331)
if (mySocket.connected){
var sym:SimpleButton;
sym.addEventListener(MouseEvent.MOUSE_DOWN, symbtn);
function symbtn(event:MouseEvent):void {
mySocket.writeBytes(1);
}
}
I'm not sure why you are using writeBytes(), which writes an array of bytes, to write a single value. Why not use the writeByte() method, instead?
[edit]
The flash application is connecting to port 5331. What do you have connecting that port to the serial port that the Arduino is listening to?[/edit]
Ok I just realized I left out that I'm using serproxy to connect flash to the arduino and yes the flash application connects to serproxy fine. I just can't figure out why the data that's sent out isn't getting to the arduino.
Yes I have and I know i could use firmata and as3dlue or what ever but I am avoiding having to re write my code to work for that just because I like the challenge but I can't find any help.
I can certainly understand that. But, if you can't get it to work, you might try using as3glue and firmata, just to verify that it is not hardware or permissions issue.
Once you know that the hardware works, and that you have all the right permissions to open sockets and connect the ports, then go back to the non-as3glue approach.