Hello all. I have the following code on my Arduino Uno (1.03). I want to know if I can send x, y coordinate values, such as (4,8), from the serial port to the Arduino (Uno) and have the arduino recognize that it is getting xy coordinates so they can be parsed out.
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 loop() {
if (stringComplete) {
if (inputString == "valve\n") {
cycleValve();
Serial.write("R");
} else if (inputString == "(*,*)\n") {
//code to parse inputString to get numbers out as x and y
Serial.write("R");
}
}
}
Is there some way to put in a wildcard, such as '*' to be used in a comparison statement with '=='?
I want to know if I can send x, y coordinate values, such as (4,8), from the serial port to the Arduino (Uno) and have the arduino recognize that it is getting xy coordinates so they can be parsed out.
You can send the coordinates. The Arduino can read and store them, then parse the packet, when it has a complete packet. Knowing that the packet represents coordinates, without any identifying information in the packet is not possible.
Is there some way to put in a wildcard, such as '*' to be used in a comparison statement with '=='?
What does this mean? You can compare a String (ugh!) to '*'. But, why?
Basically I want the Arduino to know it is receiving coordinates (some numbers between parentheses separated by a comma) in the structure I laid out in my code above without having to re-write it all (as I have already written quite a bit of code in this structure).
I know it won't work, but am stuck trying to figure out how to make something work. It doesn't need to be the ,...I just need it to know it is getting coordinates, and they won't always be the same.
Maybe I can do something like this?
stringOne = "(0,0)";
if (stringOne.compareTo(inputString) > 0 ) {
// parse out x and y from inputString here
// and always have the coordinates be greater than 0,0
}
Or maybe simpler:
stringOne = "(0,0)";
if (inputString >= stringOne ) {
// parse out x and y from inputString here
// and coordinates greater than or equal to 0,0 will work
}
Problem now is that sometimes I'll want negative coordinates....