noobie question to create a string from other strings
in
Contributed Library Questions
•
7 months ago
Hi, I am having a problem with creating strings in processing. Basically I have data coming in that is an integer and I would like to concatenate it with existing characters. And then send that string out in a UDP packet to an arduino. so overall i am having a simple data conversion problem with conversion between strings, and string arrays. I'm pretty sure i dont want it to be a string array because it wont send correctly. I have posted the code i have so far below:
- import oscP5.*; // Load OSC P5 library
- import netP5.*; // Load net P5 library
- import processing.serial.*; // Load serial library
- import hypermedia.net.*;
- UDP udp; // define the UDP object
- String ip = "192.168.1.177"; // the remote IP address
- int port = 8888; // the destination port
- int xsize = 100;
- int ysize = 100;
- int NUM_PWM_PINS = 6;
- String addr;
- float val;
- float [] fader = new float[NUM_PWM_PINS];
- float [] m = new float[NUM_PWM_PINS];
- int [] x = new int[NUM_PWM_PINS];
- int i;
- int [] pin = {3,5,6,9,10,11};
- int j;
- int [] toggle = {0,0};
- char arduinoID = '1';
- char command = 'A';
- char terminator = '@';
- String [] commands = {"A", "a", "D", "d"};
- String [] pins = {"03", "05", "06", "09", "10", "11"};
- OscP5 oscP5; // Set oscP5 as OSC connection
- void setup()
- {
- size(xsize,ysize); // Processing screen size
- oscP5 = new OscP5(this,8000); // Start oscP5, listening for incoming messages at port 8000
- udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000
- //udp.log( true ); // <-- printout the connection activity
- udp.listen( true ); // and wait for incoming message
- }
- void oscEvent(OscMessage theOscMessage)
- {
- addr = theOscMessage.addrPattern();
- if(addr.indexOf("/1/fader") !=-1)
- { // Filters out any toggle buttons
- i = int((addr.charAt(8) )) - 49;
- fader[i] = theOscMessage.get(0).floatValue();
- x[i] = int(map(fader[i], 0, 1, 0, 255)); //a value from 0-255 #####This is the value I want to concatenate ########characters labeled above as 'handshake', ' command', and 'pin' number
- if (toggle[j] == 1)
- {
- //udp.send("!A12000@", ip, port); //this is an example of what needs to be sent from this program with the value of "200" being the integer of x[i]
- }
- if (toggle[j] == 0)
- {
- //udp.send("A06255@", ip, port); //this is an example of what needs to be sent from this program with the value of "255" being the integer of x[i]
- }
- }
- if(addr.indexOf("/1/toggle") !=-1)
- {
- j = int((addr.charAt(9) )) - 49;
- toggle[j] = int(theOscMessage.get(0).floatValue());
- println(toggle[j]);
- }
- }
- void draw()
- {
- background(255);
- if (toggle[0] == 1)
- {
- fill(x[0],x[1],x[2]);
- ellipse((xsize/2-xsize/4), ysize/2, xsize/4,ysize);
- }
- else if(toggle[1] == 1)
- {
- fill(x[3],x[4],x[5]);
- ellipse((xsize/2+xsize/4), ysize/2, xsize/4, ysize);
- }
- else
- {
- for(i=0; i<6; i=i+1)
- {
- m[i]=0;
- }
- }
- }
- /*void receive( byte[] data )
- { // <-- default handler
- //void receive( byte[] data, String ip, int port ) { // <-- extended handler
- for(int i=0; i < data.length; i++)
- print(char(data[i]));
- println();
- }*/
1