We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all. I have a question regarding sending data back from Arduino to an Android tablet to change sliders on a GUI built with Processing for Android and the Ketai library. I have a button on the gui that prompts Arduino to dump the contents of an array back to the android device in order to set controlp5 slider values as part of a preset function for a synthesizer project I am working on. I am using Ketai Bluetooth library and the onBluetoothDataEvent function to read the data sent back from the Arduino into an array and use the contents of that array to change the slider values. The function looks like this:
public void onBluetoothDataEvent(String who, byte[] data)
{
int test1;
int sliderV;
// KetaiOSCMessage m=new KetaiOSCMessage(data);
if (isConfiguring)
return;
//received
info += new String(data);
//if(info.length() > 100) //clean the words on screen if string to long
//info = "";
KetaiOSCMessage ardRecv= new KetaiOSCMessage(data);
byte cnt;
for (cnt=0;cnt<23;cnt++){
dataInt=data;
}
}
the data from dataInt is then used in a function called "preset()" that changes the sliders accordingly:
void preset()
{
println(dataInt);
//gui.getController("attack").setValue(34);
slider4.setValue(int(dataInt[5]));
//slider5.setValue(dataInt[6]);
//slider6.setValue(dataInt[8]);
//slider7.setValue(dataInt[0]);
}
The values look right. I get a list from 0 to 22 like this:
[0] 22
[1] 18
[2] 32
[3] 10
[4] 37
[5] 67
[6] 85
[7] 63
[8] 0
[9] 55
[10] 44
[11] 12
[12] 89
[13] 51
[14] 115
[15] 9
[16] 39
[17] 102
[18] 80
[19] 21
[20] 12
[21] 115
but when I try to use the data to change the slider values I get these errors:
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at controlP5.ControlBroadcaster.invokeMethod(Unknown Source)
at controlP5.ControlBroadcaster.callTarget(Unknown Source)
at controlP5.ControlBroadcaster.broadcast(Unknown Source)
at controlP5.Controller.broadcast(Unknown Source)
at controlP5.Button.setValue(Unknown Source)
at controlP5.Button.activate(Unknown Source)
at controlP5.Button.mouseReleased(Unknown Source)
at controlP5.Controller.setMousePressed(Unknown Source)
at controlP5.ControllerGroup.setMousePressed(Unknown Source)
at controlP5.ControlWindow.mouseReleasedEvent(Unknown Source)
at controlP5.ControlWindow.mouseEvent(Unknown Source)
at controlP5.ControlWindow.draw(Unknown Source)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet.handleMethods(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PGraphicsAndroid2D.requestDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:856)
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=2; index=5
at processing.test.fmdx_a0_g.FMDX_A0_g.preset(FMDX_A0_g.java:1090)
at processing.test.fmdx_a0_g.FMDX_A0_g.Wave(FMDX_A0_g.java:1008)
... 23 more
and then it all goes to s**t. :(
Would anyone be able to help me with this? I think its something to do with an out of bounds array exception but I'M NOT SURE. Any help seriously appreciated. Its driving me round the bloody twist. Thanks,
Steve.
Answers
There error message is rather explicit, stating that the size of your array is
2
and that you attempt to access position5
inpreset()
. I don't know where you're going wrong...I'm still trying to work this out... Thanks for the help. :)