Hi, I'm new at arduino. So far with some help and a lot of research I have managed to get my arduino talking to flash using a light sensor or a potentiometer.
The code in the environment reading in this case from a light sensor is this:
[processing code start]
int firstSensor = 0; // first analog sensor
void setup()
{
Serial.begin(9600);
}
void loop()
{
firstSensor = analogRead(0);
delay(10);
Serial.print(firstSensor, DEC);
Serial.print(0, BYTE);
delay (50);
}
[processing code end]
The code in the serproxy config file is this:
[serproxy code start]
Config file for serproxy
See serproxy's README file for documentation
Transform newlines coming from the serial port into nils
true (e.g. if using Flash) or false
newlines_to_nils=true
#The USB port that the Arduino is connected to
serial_device1=/dev/tty.usbserial-A60049Co
#Comm ports used
comm_ports=1,2,3,4
***set the baud rate
comm_baud=9600
#Default settings
comm_databits=8
comm_stopbits=1
comm_parity=none
Idle time out in seconds
timeout=300
Port 1 settings (ttyS0)
net_port1=5334
Port 2 settings (ttyS1)
net_port2=5332
Port 3 settings (ttyS2)
#net_port3=5333
Port 4 settings (ttyS3)
net_port4=5331
[serproxy code end]
The flash actionscript code is this:
[flash as code start]
createSocket ();
function createSocket () {
serialServer = new XMLSocket ();
trace ("made it" + serialServer);
//127.0.0.1 is the same as "localhost" ie an alias to your local machine
//it is concievable to that you would want to connect from another machine and you would change this
serialServer.connect ("127.0.0.1", 5331);
serialServer.onConnect = function (success) {
trace ("connected " + success);
serialServer.send ("HOWDY FROM FLASH" + new Date().toString());
};
serialServer.onClose = function () {
trace ("closed");
};
serialServer.onData = function (data) {
trace ("incoming" + data);
test = data;
test = Math.round((data / 4)*2 );
test = test /10
trace (test);
_root.ball._xscale = test;//scale the ball based on the changing variable.
_root.ball._yscale = test;
_root.output1_txt.text = ("test" + test);
_root.output2_txt.text=("serialServer" + serialServer);
_root.output3_txt.text=("incoming data" + data);
//mcpos = Math.round(data / 100 *2);
//mc1.gotoAndStop(mcpos);
//trace (mcpos);
};
}
[flash as code end]
This works just fine and I can control an animation by the numbers read from the sensors. The problem I'm having now is getting more than one sensor controlling more than one animation i.e. each individual sensor controls a seperate animation. I have researched and cannot find any specific examples to help me and I have tried coding flash and processing with disastrous nonsensical results.
Has anyone any experience or solutions to this? I'm not sure whether I should be trying to work on the serproxy config, the flash code, processing code etc or even if it's a combination (which I'm sure it is, but can't at the moment get my head around the logic). Any help is appreciated on this, I'll put up further info if needed. Thanks very much for any help.