Loading...
Logo
Processing Forum

Input parsing failure

in Programming Questions  •  4 months ago  
Hello all.

I have a foot pedal hooked to an Arduino that sends a line formatted as such when the switches state changes:

  "ButtonEvent":args[0]:args[1]:args[2]:args[3]
    args[0] = 0 (down), or 1 (up)
    args[1] = pin number
    args[2] = default 0
    args[3] = default 0

It gets received in one piece using serialEvent, and sent to the following function:

void parseInput(String input) {
  println("Received: " + input);
  String args[] = input.split(":");
  println(args);
  if (args[0] == "ButtonEvent") {
    println("Button Event.");
    if (args[2] == "2") {
      println("Button 2. ");
      if (args[1] == "0") {
        myRobot.keyPress(KC);
        println("KEY DOWN");
      } else {
        myRobot.keyRelease(KC);
        println("KEY UP");
      }
    }
  }
}

I get the following output every time I push the pedal down:

Received: ButtonEvent:0:2:0:0

[0] "ButtonEvent"
[1] "0"
[2] "2"
[3] "0"
[4] "0
"

And this when I let it back up:

Received: ButtonEvent:1:2:0:0
[0] "ButtonEvent"
[1] "1"
[2] "2"
[3] "0"
[4] "0
"

As you can tell, this is obviously not what the code is supposed to do, and It is not working. If I comment out the args[0] == "ButtonEvent" line, It still does not get the args[2] == "2".

The foot switch is connected to Pin 2, so that is normal. And argument 1 is fine. But the code seems to disagree. I have the multiple pin support so that I can expand it to 10 or so switches (Can, not will).

Any help would be greatly appreciated.

Replies(2)

Look at the String entry of the Reference, particularly how to compare strings....
Also in the wiki: Why don't these Strings equal?
Alright, good to know.
use String.equals("BLAHDYBLAHDYBLAH");

My Github: https://github.com/choltfo/
My website: http://choltfo.zzl.org/