We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Representing serial data (Read 694 times)
Representing serial data
Feb 7th, 2009, 12:38am
 
Hi, i am trying to comunicate arduino sending data, captured by a LDR, to be recieved from processing and translated to an animation, an interaction. I can comunicate the two aplications, i can read the values from arduino printed in the printboard of processing, but i dont know why doesn't process the function well.

i paste the both codes below: arduino and processing, if somebody can help me to resolve this problem. thanks a lot

processing:

////////////////////////////////////////////////////////////////
import processing.serial.*;
Serial port;

////////////////////////////////////////////////////////////////
int val;
int myString;

////////////////////////////////////////////////////////////////
BlinkingEye eye1;
float y;
float x;

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
void setup()
{
 size(200,200);

 port = new Serial(this,"/dev/cu.usbserial-A9005f9C",9600);
// println ("port: /dev/cu.usbserial-A9005f9C");
// println(Serial.list());
   
 frameRate(25);
 smooth();
 background(255);
 //noCursor();

 eye1 = new BlinkingEye(width, height);
 //eye2 = new BlinkingEye(width, height);  
}

////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
void draw()
{

 background(255);
 noStroke();


 byte[] buffer = new byte[val];

 while (port.available() > 0) {
   buffer = port.readBytes();
   port.readBytes(buffer);

   if (buffer != null) {
     String myString = new String(buffer);
     println(myString);
   }
 }
//please someone can explain me this part?(the while and if)

 if(myString < 900){
   x = 100;
   y = 60;
 }
 else{
   x = 60;
   y = 60;
 }

 eye1.update(x, y);

 eye1.draw();

}
*the code for the class is declared in a new tab.



arduino:

//mostrar valores processing


int pinLed= 10;
int pinLDR = 2;

int myString;
int val=0;



void setup() {
 pinMode(pinLed, OUTPUT);
}


void loop() {
 Serial.begin(9600);
 val = analogRead(pinLDR);
 myString = analogRead(pinLDR);
 
 Serial.println(val);

 
 if(Serial.available())
 {
   val = Serial.read();
   
 }
 if(val < 900) //valor variable en consonancia a la luz y la sensibilidad del LDR
 digitalWrite(pinLed,LOW);
 
 else
 digitalWrite(pinLed,HIGH);
 
 
 delay(1000);
}
Page Index Toggle Pages: 1