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);
}
I'm actually having trouble with this as well. However, I cannot even get flash to communicate to arduino at all! (ie, no RX light even...).
I'm using Actionscript 3.0,
tinkerproxy (with the configuration file set correctly according to several tutorials I've found... and it makes sense to me too lol)
and an arduino uno with the USB input.
So I'm bumping this post rather than writing a new one-
How can I get flash to communicate with arduino and visa versa?
there are a bunch out there- I use Adobe Flash CS4. Flash is really the only actionscript-utilizing thing I know much about... but I think theres something called Adobe Flex that also uses it- but it is without a lot of the graphical/animation capabilities of Flash (i think...)
Anyways- the fact still stands. There is not a good tutorial of exactly what is required to send a value from flash to arduino and the other way around. They all skip corners and I'm left very confused
So if anyone can post any help on the subject, I will greatly appreciate it
@ kasperkampermann: thank you for the info. maybe you can help me with one question.
i try to drive a stepper motor form flash connected via a easydriver board. i got it turning already using a (flash)timer. my issue is, that it turns quite slowly even if i set the timer to 1ms. do you know how i can turn it faster with flash?