Arduino and Osc thru processing
in
Contributed Library Questions
•
2 years ago
i have written the folowing code and when i run it i get an error : arrayIndexOutOfBoundsExcepton: 0
- import oscP5.*;
import netP5.*;
import processing.serial.*; - Serial arduinoPort;
OscP5 oscP5; - int motor1 = 0;
int motor2 = 0;
int [] m1 = new int [2];
int [] m2 = new int [2]; - void setup()
{
size(200,100);
noStroke();
oscP5 = new OscP5(this,8000);
arduinoPort = new Serial(this, Serial.list()[0], 9600);
}
void oscEvent(OscMessage theOscMessage)
{
{
String addr = theOscMessage.addrPattern();
if(addr.indexOf("/1/toggle") !=-1){
int i = int((addr.charAt(9) )) - 0x30;
m1[i] = int(theOscMessage.get(0).floatValue());
}
}
{
String addr = theOscMessage.addrPattern();
if(addr.indexOf("/2/toggle") !=-1){
int i = int((addr.charAt(9) )) - 0x30;
m2[i] = int(theOscMessage.get(0).floatValue());
}
}
}- void draw() {
background(225); - if(m1[1] == 0){
arduinoPort.write("l");
motor1 = 0;
}
if(m1[1] == 1){
arduinoPort.write("L");
motor1 = 255;
}
fill(motor1,0,0);
ellipse(50, 50, 50, 50);
if(m2[1] == 0){
arduinoPort.write("l");
motor2 = 0;
}
if(m2[1] == 1){
arduinoPort.write("L");
motor1 = 255;
}
fill(motor2,0,0);
ellipse(50, 100, 50, 50);
}
1