I want to send data from Arduino to Flash and the other way around. I already figured out the way from Arduino to flash, I use serproxy and a simple serial print with a delay in Arduino. This is the as3 code:
import flash.utils.Timer;
import fl.transitions.easing.*;
import fl.transitions.Tween;
var arduinoSocket:Socket;
init();
function init()
{
openArduinoSocket();
}
function openArduinoSocket()
{
arduinoSocket = new Socket("localhost",5331);
arduinoSocket.addEventListener(Event.CLOSE, closeHandler);
arduinoSocket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler);
}
function closeHandler(event:Event):void
{
trace("[Workaround] Socket closed, reopening...");
openArduinoSocket();
}
function socketDataHandler(event:ProgressEvent):void
{
arduinoSocket.writeUTFBytes("H");
var str:String = arduinoSocket.readUTFBytes(arduinoSocket.bytesAvailable);
}
I can not find out how it would work the other way around.
If I edit the socketDataHandler function into this:
function socketDataHandler(event:ProgressEvent):void
{
arduinoSocket.writeUTFBytes("H");
var str:String = arduinoSocket.readUTFBytes(arduinoSocket.bytesAvailable);
}
I would expect flash to send an H over the serial connection. If I upload the physicalPixel example to my Arduino and add a simple Serial.println in the beginning the Led does not turn on as I would expect. Here the arduino code:
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
Serial.println("test");
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
delay(200);
}
Can anybody help me out? Thanks already