Hey Guys,
Been toiling with this almost constantly for 48 hrs.
I've come a long way! But I'm going a bit mad and I would really appreciate a bit of help.
I'm using touch designer to send a string via serial to the arduino
The code in touch is
n=op('chopto1')
w=n[0,0]
x=n[0,1]
y=n[0,2]
z=n[0,3]
op('serial1').send("%d" %w,"%d" %x,"%d" %y, "%d" %z , terminator="\n")
This should deliver the string 32,73,18,99 to the arduino running
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
int start = 0;
int pad1 = 0;
int pad2 = 0;
int pad3 = 0;
String lights[4];
void setup() {
// initialize serial:
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
ParseSerialData();
Serial.println(start);
// clear the string:
inputString = "";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
void ParseSerialData() {
int padNum = 0;
int q = 0;
for (int i = 0; i < inputString.length(); i++){
if (inputString.substring(i, i+1) == ","){
lights[padNum] = inputString.substring(q,i);
padNum ++;
q = i + 1;
}
if (i == inputString.length() - 1 ){
lights[padNum] = inputString.substring(q,i);
}
padNum = 0;
q = 0;
start = lights[0].toInt();
pad1 = lights[1].toInt();
pad2 = lights[2].toInt();
pad3 = lights[3].toInt();
}
}
Which as far as I can tell should return the first value in the inputString (32) to touch design via the Serial.println(start)
When I run the script in touch i get all 4 values printed back on separate lines, can anyone see the problem? Thanks
Alex
string_to_int_vars_parse.ino (1.54 KB)