Go Down

Topic: variables? (Read 723 times) previous topic - next topic

xhlin

Oct 25, 2006, 12:20 am Last Edit: Oct 25, 2006, 12:20 am by xhlin Reason: 1
hi!
is it possible to declare a variable in the arduinoCode and recieve it through flash?
i have tried the FlashConversation.fla, working fine but the code is to complex for me to clean up.
could someone offer me the most simple piece of code that can recieve a number from arduino to flash, please!

Eric

#1
Oct 25, 2006, 10:13 am Last Edit: Oct 25, 2006, 11:43 am by Eric Reason: 1
Hello,

I always use the 'Serial Server' created by Dan O'Sullivan.

Read the instructions, after installing, start the server with:
java -jar ss6.jar SerialPort:COM1 Baud:9600 SocketPort:9001 Sub0ForChar:10 SerialDriver:Sun
(maybe you have to change your serialport):

You can use the 'debug' checkbox to check if the 'serial server' receives any value.
If it works you can start Flash and use this code:

Code: [Select]

createSocket();
function createSocket() {
     serialServer = new XMLSocket();
     trace("new xmsocket");
     
     serialServer.connect("127.0.0.1", 9001);
     
     serialServer.onConnect = function(success) {
           trace("connected " + success);
     };
     
     // when you close the serial port
     serialServer.onClose = function() {
           trace("closed");
     };
     
     //receive some data from the arduino
     serialServer.onData = function(data) {
           trace("incoming = " + data);
     };
}

// send data to the arduino
this.onMouseDown = function() {
     serialServer.send("A");
     trace("Mouse Down");
};

stop();



xhlin

does it work with ,  Serial Proxy?
and what code do you fill your arduino with, simpeMessageSysyem?

regards
xh|in

Eric

You can use this code to send data from Arduino to flash:
Code: [Select]

void setup() {
 Serial.begin(9600);
}

void loop() {
 Serial.println("Hello Flash, this is Arduino");
 delay(400);
}

Daniel Guse

#4
Oct 30, 2006, 11:01 pm Last Edit: Oct 30, 2006, 11:07 pm by Daniel_Guse Reason: 1
Hi!

I tried to connect Arduino (0005) and Flash 8. But there are two strange things happening:

- 1 -

When I read the Serial monitor in Arduino, there are only "0"s (zeros) when I press a pushbutton (connected to I/O Pin 5), but when I release this pushbutton, there are both, "0"s and "1"s (00011100000011111000111 and so on). Actually, there should be only "1"s, right?! Why does this happen?

Here's my Arduino-Code:

---

int ledPin = 13; // LED connected to digital pin 13
int inPin = 5;   // pushbutton connected to digital pin 5
int val = 0;     // variable to store the read value

void setup()
{
 pinMode(ledPin, OUTPUT);      // sets the digital pin 13 as output
 pinMode(inPin, INPUT);      // sets the digital pin 7 as input
 Serial.begin(9600);      // opens serial port, sets data rate to 9600 bps
}

void loop()
{
 val = digitalRead(inPin);   // read the input pin
  digitalWrite(ledPin, val);    // sets the LED to the button's value

 // Serial.print(val, DEC);  // send the buttons's value to serial port

   // say what you got:
   //Serial.print("I received: ");
   Serial.println(val, DEC);
 
}


---


- 2 -

Another problem occurs in Flash. I'm using a proxy by D.Mellis, that works fine so far. Flash can hear Arduino and trace the received values. But, when I use an "if"-loop, it seems to be ignored. Here's my Actionscript-Code:

---

     
     createSocket();
     
function createSocket() {
     serialServer = new XMLSocket();
     trace("new xmlsocket");
     
     serialServer.connect("127.0.0.1", 5337);
     
     serialServer.onConnect = function(success) {
           trace("connected " + success);
     };
     
     // when you close the serial port
     serialServer.onClose = function() {
           trace("closed");
     };
     
     //receive some data from the arduino
     serialServer.onData = function(data) {
           trace("incoming = " + data);
           
           // begin if-loop            
           if (data == "0") {
                 meinRechteck.start();
                 trace("VERTICAL");
                 }
           else {
                 meinRechteck.stop();
                 trace("HORIZONTAL");
                 }
     } };

stop();


---

And this is, what is traced:

incoming = 0

HORIZONTAL
incoming = 1

HORIZONTAL


So, there is always "HORIZONTAL" traced, but i want "VERTICAL" if data == "0" !


Maybe someone can help me?! Any ideas? Thanks a lot!

Daniel

Eric

1)
Did you use a resistor as you can see in this tutorial?


2)
I don't really know, but you could try this to find out and locate the problem:

trace("type = " + typeof(data));
trace("string length = " + data.length);

So the datatype should be a 'string' and the length should be '1'
I

Daniel Guse

Hej ya!

So, I set up the whole thing like in the tutorial and now the serial output is ok!  :) Thanks a lot, Eric!

But:

I traced the lenght and type of 'data' in Flash 8:

data is a string (ok) and the length is 2 (not 1)!


Does anyone know how to solve this problem?


Thanx a lot for your support...

Daniel.

Eric

I think you only want the first character,
the second is probably a 'space'.

The actionscript code for this is:

Code: [Select]

trace(data.substr(0,1));


It will only show the first character.

Eric

Go Up