Hi! I manged to get arduino talking to flash! I can make the "Blink" program work though flash. Hurray!
I have a couple of questions. I have the following code which outputs values though the serial port from a sensor when uploaded to arduino using the normal arduino program :
// www.plusea.at
// reads analog input from the five inputs from your arduino board
// and sends it out via serial
// variables for input pins and
int analogInput0 = 0;
// variable to store the value
int value0 = 0;
void setup(){
// declaration of pin modes
pinMode(analogInput0, INPUT);
// pullup resistors
digitalWrite(14, HIGH);
digitalWrite(15, HIGH);
digitalWrite(16, HIGH);
digitalWrite(17, HIGH);
// begin sending over serial port
Serial.begin(9600);
}// end setup
void loop(){
// read the value on analog input
value0 = analogRead(analogInput0);
// print out value over the serial port
Serial.print(1, BYTE); //prefix
Serial.print(value0);
Serial.print(10, BYTE); //end signal
// wait for a bit to not overload the port
delay(100);
}// end loop
First question- if i want to interface with flash and use AS3glue, do i need to "translate" this into as3glue format? or just upload it to the arduino using the normal program before closing it and opening flash?
Second question - i want to use the analog input from the sensor to act in a similar way to the mouse click in the following code, so when it goes over a certain threshold it causes something to happen? How on earth can i code this into the flash program? Here is my existing code...
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class AvoiderGame extends MovieClip
{
public var army:Array;
public var enemy:Enemy;
public function AvoiderGame()
{
army = new Array();
var newEnemy = new Enemy( 100, -30 );
army.push( newEnemy );
addChild( newEnemy );
stage.addEventListener(MouseEvent.CLICK, onClick);
}
public function onClick( event:MouseEvent ):void
{
var randomX:Number = (Math.random() * 200) + 100;
var randomY:Number = (Math.random() * 150) + 50;
var newEnemy:Enemy = new Enemy( randomX, randomY);
army.push( newEnemy );
addChild( newEnemy );
trace("click");
}
}
}
Any help at all would be greatly appreciated! Even if it's to tell me that it's too complicated?
Huge thanks,
Susan