jansensan
YaBB Newbies
Offline
Posts: 6
qc, can
flash (as3) to processing to arduino
Nov 17th , 2008, 3:20am
hello i recently decided to communicate to arduino via processing. that worked really well, using the arduino library for processing (http://www.arduino.cc/playground/Interfacing/Processing). i also used as3 to communicate with processing, using the xml socket object in flash, that worked pretty well too. so i thought i would create myself a processing app to forward the info from flash to arduino. the only problem i encounter is when the data is received from flash, processing seems unable to parse it properly. i would gladly join a zip of my project, but i dont see that option with my post, so here's the processing code: // --- --- --- imports --- --- --- // import processing.net.*; import processing.serial.*; import cc.arduino.*; // --- --- --- variables --- --- --- // Arduino arduino; int qtyArduinoDigPins = 13; int port = 8080; Server server; Client client; byte endByte = 0; String input; int pinInput; String valueInput; // --- --- --- setup --- --- --- // void setup (){ size (320, 240); println(Arduino.list()); arduino = new Arduino(this, Arduino.list()[0], 115200); for (int i = 0; i <= 13; i++) { arduino.pinMode(i, Arduino.OUTPUT); } server = new Server (this, port); loop (); } void draw () { readDataFromFlash (); } void loop () { } // --- --- --- functions --- --- --- // void sendDataToFlash (String dataToFlash) { server.write (dataToFlash); /* the trick is this next line that sends the "0" termination byte unaltered and alone, this way it doesn't get evaluated with the other variables being sent */ server.write (endByte); /* "endByte" is the termination byte, which Flash's XMLSocket uses to figure out when a transmission stream has ended. This also means that any variables that are being sent as zero bytes need to be shifted (say +1, for example) and evaluated in Flash accordingly, or else Flash will kill the transmission there */ } void readDataFromFlash () { client = server.available (); if (client != null) { println("- readDataFromFlash -"); input = client.readString (); String[] dataToArduino = new String[2]; dataToArduino = split(input, ","); println("dataToArduino.length: " + dataToArduino.length); println("dataToArduino[0]: " + dataToArduino[0]); println("dataToArduino[1]: " + dataToArduino[1]); pinInput = int(dataToArduino[0]); println("pinInput: " + pinInput); valueInput = dataToArduino[1]; println("valueInput: " + valueInput); println("(valueInput == low): " + (valueInput == "low")); println("(valueInput == high): " + (valueInput == "high")); /* if (valueInput == "low") { println("write Arduino.LOW to pin " + pinInput); arduino.digitalWrite(pinInput, Arduino.LOW); } else if (valueInput == "high") { println("write Arduino.HIGH to pin " + pinInput); arduino.digitalWrite(pinInput, Arduino.HIGH); } */ } } basically, what is wrong is when i try to do that: println("valueInput: " + valueInput); println("(valueInput == low): " + (valueInput == "low")); println("(valueInput == high): " + (valueInput == "high")); even if valueInput equals to "low", both the println after trace false. any clue for that?