Help with some code needed
in
Integration and Hardware
•
1 year ago
Hello I am new here and to the world of processing and arduino.
I am trying to control the water level in a bathtub using OSCTouch, Processing and Arduino.
I wrote the code for Processing but I am having some trouble with it.
All that is required of the board is to send the a value corresponding to the Fader on my iPod to my Arduino board via serial connection.
Printing water[0] is always 0.
Every time I change the value of the fader I get this message in Proccesing:
### [2012/3/18 15:23:55] ERROR @ OscP5 ERROR. an error occured while forwarding an OscMessage
to a method in your program. please check your code for any
possible errors that might occur in the method where incoming
OscMessages are parsed e.g. check for casting errors, possible
nullpointers, array overflows ... .
method in charge : oscEvent java.lang.reflect.InvocationTargetException
Here is the code:
import oscP5.*; // Load OSC P5 library
import netP5.*; // Load net P5 library
import processing.serial.*; // Load serial library
Serial arduinoPort; // Set arduinoPort as serial connection
OscP5 oscP5; // Set oscP5 as OSC connection
int [] water = new int [1];
void setup() {
size(100,100); // Processing screen size
noStroke(); // We don’t want an outline or Stroke on our graphics
oscP5 = new OscP5(this,8000); // Start oscP5, listening for incoming messages at port 8000
arduinoPort = new Serial(this, "COM3", 9600); // Set arduino to 9600 baud
}
void oscEvent(OscMessage theOscMessage){
String addr = theOscMessage.addrPattern();
if(addr.equals("/1/fader1")){
int i = int((addr.charAt(9) )) - 0x30;
water [0] = int(theOscMessage.get(0).floatValue());
}
}
void draw() {
background(50); // Sets the background to a dark grey, can be 0-255
arduinoPort.write(water [0]);
println(water [0]);
delay(1000);
fill(water[0],0,0); // Fill rectangle with redLED amount
ellipse(50, 50, 50, 50); // Created an ellipse at 50 pixels from the left...
// 50 pixels from the top and a width of 50 and height of 50 pixels
}
Thanks in Advance,
Fouadk11
1