Need Arduino to react to Processing reading a .txt file

Hi,

I have a project where we're using Processing to read through a .txt file to pick out certain keywords. I think this is the relevant bit of that code:

      StringTokenizer st =
        new StringTokenizer(data, "\"<>,.()[] ");// break it down
      while (st.hasMoreTokens ()) {
        // each chunk of data is made 
        chunk = st.nextToken().toLowerCase() ;

        if (chunk.indexOf("democrat") >= 0 ) // found "love"?
          love++;    // increment love by 1
        if (chunk.indexOf("trump") >= 0)   // found "peace"?
          peace++;   // increment peace by 1
        if (chunk.indexOf("republican") >= 0) // found "arduino"?
          arduino++; // increment arduino by 1

in this instance, Processing is finding the words and adding to a counter, which Arduino uses to adjust the intensity of some LEDs. The Arduino code for that process looks like this:

Serial.println(inByte);      // print the value to
                            // the serial port

  if (Serial.available() > 0) {

    // read the incoming byte:
    inByte = Serial.read();

    // If the marker's found, next 6 characters are the colour
    if (inByte == '#') {

      while (pointer < 6) { // accumulate 6 chars
        buffer[pointer] = Serial.read(); // store in the buffer
        pointer++; // move the pointer forward by 1
      }

      // now we have the 3 numbers stored as hex numbers
      // we need to decode them into 3 bytes r, g and b
      r = hex2dec(buffer[1]) + hex2dec(buffer[0]) * 16;
      g = hex2dec(buffer[3]) + hex2dec(buffer[2]) * 16;
      b = hex2dec(buffer[5]) + hex2dec(buffer[4]) * 16;

      pointer = 0; // reset the pointer so we can reuse the buffer

    }
  }

  btn = digitalRead(BUTTON); // read input value and store it

  // Check if there was a transition
  if ((btn == HIGH) && (old_btn == LOW)){
    state = 1 - state;
  }

  old_btn = btn; // val is now old, let's store it

  if (state == 1) { // if the lamp is on

    analogWrite(R_LED, r);  // turn the leds on
    analogWrite(G_LED, g);  // at the colour
    analogWrite(B_LED, b);  // sent by the computer
  } else {

    analogWrite(R_LED, 0);  // otherwise turn off
    analogWrite(G_LED, 0);
    analogWrite(B_LED, 0);
   }

  delay(100);                // wait 100ms between each send
}

int hex2dec(byte c) { // converts one HEX character into a number
    if (c >= '0' && c <= '9') {
      return c - '0';
    } else if (c >= 'A' && c <= 'F') {
      return c - 'A' + 10;
    }
}

I'm trying to modify that code so that instead of turning on LEDs, Arduino turns the found word into a tone with the Piezo buzzer with the tone() function. I don't know where to start on the Arduino code to get it to receive the information from Processing (that it found a keyword) and turn it into a tone.

I hope the code I've posted here will help with some guidance. Thanks in advance for any help.

jonbearpig:
I'm trying to modify that code so that instead of turning on LEDs, Arduino turns the found word into a tone with the Piezo buzzer with the tone() function. I don't know where to start on the Arduino code to get it to receive the information from Processing (that it found a keyword) and turn it into a tone.

Is my understanding of the problem correct as follows ...

At the moment your PC program sends a message such as #1A23F4 to the Arduino and the Arduino converts that into the numbers 26, 35 and 244 for the purpose of LED brightness.

If that is correct, do you want to interpret some or all of those numbers to figure out the tone() to play?

OR, do you want to send a completely different message? If so give an example of the message and tell us if you want to send the colour messages as well as the tone messages.

...R

in this instance, Processing is finding the words and adding to a counter, which Arduino uses

Your useless Processing snippet does NOT show that it ever tells the Arduino diddly-squat.