I am working on both arduino and flash, I wanted to create a delay(like the timer function) when receiving data and display it in flash swf file.
I've successfully in displaying the data coming from arduino to flash, however, every time i pressed the pressure sensor, the data display in swf become clustered due to not having the interval/delay/timer function.
Do I need to create separate timer and create a new function and if so, how would I associate it with the "onTick2"?
a.addEventListener(ArduinoEvent.ANALOG_DATA, onTick2);
function onTick2(e:ArduinoEvent):void
{
var forceValue:Number;
var forceNum:Number;
forceValue = a.getAnalogData(0); //this is the code to get the data from the sensor data in arduino
forceNum = (forceValue/9.1);
myFormat = new TextFormat();
myFormat.font = "Arial";
myFormat.size = 36;
myFormat.color = 0xFFFFFF;
myText = new TextField();
myText.x = 250;
myText.y = 240;
myText.text ="\n"+forceNum.toString()+" Avg. Pressure";
myText.height = 200;
myText.width = 200;
myText.defaultTextFormat = myFormat;
addChild(myText);
}
It is not entirely clear what you are asking (data being "clustered") but a few things –
You are creating a new
TextField
on everyArduino
event and adding them as children. Do you wish to have all the past events display or are you just wanting to display the current Arduino data in a single, persistent TextField?If the former, you probably want to move them around a little bit. Right now you are stacking them on top of each other.
if the latter (which my guess is what you want), you should create your TextField outside of that function (e.g. before you add the eventListener. Be sure to give the Textfield a name so you can reference it.
Then in your function you would only assign the data to the previously created TextField container.
(I use AS3 classes in Flex and forget exactly how Flash deals with things (no typeDef, public/private, etc. but the gist of the code is, I believe, correct.)
Oh wait – I see you are adding a line return before each new bit of data. Is that what you intend? If so, you probably need to set these additional properties: