The easiest way I can think of is sending the array with the values separated by commas.
GUI
First of all in my personal experience, making a GUI for user input in Processing is difficult, because you don't have predefined classes (as far as I know) to make text fields, check boxes, etcetera, so you would have to draw rectangles and program mouse and key events to change focus between fields. However, you could create a JFrame
and Text Fields and everything, and still use Processing's serial communication, you would end up with a window running the sketch and an external window with your GUI. Here's some information about how to create frames and other elements. Remember that Processing is actually running on Java (sorry if that's not the correct term).
But if you are going to do that, you might as well switch to "pure" Java
Sending data over serial
Processing
First you will need to build the array with your GUI, I have two ideas for that, either 16 fields, one for each row, where you write a number and it converts it to binary, or, making a group of checkboxes, 24x16, and each one represents a LED, so you tick the LEDs you want to turn on.
To send the data from Processing/Java to Arduino, here's an example code:
for(int i = 0; i < 16; i++){
if(i > 0){
str += ",";//We add a comma before each value, except the first value
}
str += frame[i];//We concatenate each number in the string.
}
serial.write(str);
}
Where frame[]
is the data you want to send to Arduino.
You have to import a special library to use serial communication. And create a class object (not sure if I'm using the correct term).
import processing.serial.*
void setup(){
/* Some setup code here */
/* Opening first port, 9600 baud rate */
Serial serial = new Serial(this,Serial.list()[0],9600)
}
Arduino
Then, on Arduino
, inside loop()
you use something like this:
String content = "";
if (Serial.available()) {
while (Serial.available()) {
content += Serial.read();
}
}
long data[16]; //The results will be stored here
for(int i = 0; i < 16; i++){
int index = content.indexOf(","); //We find the next comma
data[i] = atol(content.substring(0,index).c_str()); //Extract the number
content = content.substring(index+1); //Remove the number from the string
}
Now data[]
has the data you sent from Processing.