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.
IndexProgramming Questions & HelpPrograms › help! read values from arduino...
Page Index Toggle Pages: 1
help! read values from arduino... (Read 377 times)
help! read values from arduino...
Sep 19th, 2006, 2:34pm
 
Hi I have just written a program that reads values through the analog input port on the arduino. These values need to be recognized in processing and linked to a certain audio file, and play this (I have used the Sonia library for sound playing). Something is wrong, and I don't understand what.

***Arduino code:***


#include <SimpleMessageSystem.h>
 int b;
 int c;
void setup()
{
 Serial.begin(9600);
 
}

void loop()
{
 b = analogRead(1)
 if (b>10){
   if (b<150){
     c=1;
   }else if (b<300){
     c=2;
   }else if (b<450){
     c=3;
   }else if (b<600){
     c=4;
   }else if (b<750){
     c=5;
   }else{
     c=6;
   }
   serialWrite('A');
   serialWrite(c);
   serialWrite('B');
 }

}

void readpins(){
      b = analogRead(1);
}

 


***Processing code:***


import pitaru.sonia_v2_9.*;
import processing.serial.*;

Serial port;
String portname = "tty.usbserial-151";  
int baudrate = 9600;
int value, valueOld;
Sample sound1, sound2, sound3, sound4, sound5, sound6;
String buf="";
 
void setup() {
 Sonia.start(this);
 size(800,600);
 port = new Serial(this, portname, baudrate);
 println(port);
 fill(50);
 noStroke();
 framerate(110);
 sound1=new Sample("geluid1.wav");
 sound2=new Sample("geluid2.wav");
 sound3=new Sample("geluid3.wav");
 sound4=new Sample("geluid4.wav");
 sound5=new Sample("geluid5.wav");
 sound6=new Sample("geluid6.wav");
 valueOld = 0;
}
void serialEvent(int serial){
 // if serial event is not a line break
 if(serial!='A') {        
   // add event to buffer
   if (serial>=0){
     buf += char(serial);
   }          
 }
 else {  
 value = (buf); // we inverse the value by subtracting it from the maximum    //}
   buf="";

 }
 // println("LDR: "+value1);

}

void draw(){
 if (value!=valueOld){
     valueOld = value;
   if (value==1){
     sound1.play();
    }
   if (value==2){
     sound2.play();
   }
   if (value==3){
     sound3.play();
   }
   if (value==4){
     sound4.play();
   }
   if (value==5){
     sound5.play();
   }
   if (value==6){
      sound6.play();
   }
 }
}


I hope someone can help me out! thanks a lot!
Re: help! read values from arduino...
Reply #1 - Sep 19th, 2006, 3:03pm
 
This line of code is problematic:

value = (buf);

buf is a String and value is an integer.  You cannot set an integer to a String without converting it first.  

value = int(buf);

Re: help! read values from arduino...
Reply #2 - Sep 19th, 2006, 3:21pm
 
and that's all?
i'll try it tonight!
thanks!
Page Index Toggle Pages: 1