Pages: [1]   Go Down
Author Topic: Serial input  (Read 451 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 4
Arduino rocks! Go Arduino!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 642
Posts: 50365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 137
Posts: 6792
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

}
Logged

Pages: [1]   Go Up
Jump to: