Go Down

Topic: Serial input (Read 477 times) previous topic - next topic

GreenpeaceGeek

If I assign two variables values, how would I set it up so serial would take that input? Let's say I said
Quote

int no = 1;
int yes = 0;

. If I did that, how could I get serial to recognize yes or no if I typed them in and add that to an unsigned string.

P.S. I know Python, but I'm a complete beginner when it comes to programming for the Arduino.


PaulS

Quote
Let's say I said...


I'm following that...

Quote
If I did that, how could I get serial to recognize yes or no if I typed them in and add that to an unsigned string.


I'm not following that. Typed what in where?

Strings are NULL terminated arrays of characters. They are neither signed or unsigned.

Let's say you try again to explain the question. Please.

westfw

In order to recognize "keywords" input from the serial port, you have to assembled individual bytes from Serial.read() into a string, and write code to compare the string against a table of strings in your sketch.  Essentially, you write a whole "parser."

I take it that this is easier in Python?

jopiek

So it is much easier to just use 0 or 1 and then use that in the rest of your program!

You can then make a variable e.g.:

int input = Serial.read();

if (input == yes) {

}
if (input == no) { //could be done of couse also with else

}

Go Up