I'm doing a simple project which requires me to link the flash(actionscript 2) to arduino. Apparently, its not as simple as I thought. o.O
Basically, I'm suppose to click a button from the flash to activate the LED.
However I have tried several ways and its still not lighting up.
This is the arduino programming that I have wrote.
int activeLED ;
void setup(){
Serial.begin(9600); //setup serial conversation at 19200 bauds
pinMode(2, OUTPUT); // sets the digital pins 2 as output
}
void loop () {
//------------------------------------------------------------------------ LED LOGIC
// checks if a serial message has arrived to the board
if(Serial.available() > 0) {
//must be a request to light up an LED
//activeLED should be 2, but in binary it will come in as 50
activeLED = Serial.read();
}
if(activeLED= 50) {
//a valid LED signal has been received from Flash
// convert the byte to an int - getting ready for digitalWrite()
int outputPort = activeLED-48;
Serial.print("Requesting LED port:");
Serial.println(outputPort);
// then turns your selected LED ON
digitalWrite(outputPort, HIGH);
// when we're done, default the activeLED to nothing
activeLED = 0;
}
else if (activeLED) {
Serial.print("Requesting invalid LED port:");
Serial.println(activeLED,BYTE);
}
//slows down the visualization: each sentence will be emitted every .5 seconds
delay(50);
}
This is the coding in my flash (actionscript 2)
import Arduino;
var port:Number = 5331;// What socket port are we configured to use?
// See the net_port entries from serproxy.cfg
// Create a custom object from Flash's XMLSocket
var a:Arduino = new Arduino(port);
//------------------------------------------------------------------------ Listeners
// You can trigger custom actions by adding listners to the Arduino object. For example, you can setup your
// ActionScript code to run a setup function when Flash successfully connects to the socket listener
aListener = new Object();
aListener.onConnect = function() {
setupBoard();
};
// Binds your custom listeners to the Arduino object (a)
a.addEventListener("onConnect",aListener);
function setupBoard() {
trace("Connection established. Now setting up LEDs...");
var i = 2;
// Associates a pin with each movieclip
var mc:MovieClip = _root["mc1"+i];
// Stores the digital i/o pin number for later use
mc.pin = i.toString();
var owner = this;
mc.onPress = function() {
// Send the pin data to Arduino, telling it what pin to turn on
owner.a.send(this.pin);
}
}
Please correct my coding if there is anything wrong with it. ![]()
Really in need of help.. Thx~