Arduino functions for reading from the Serial Console
This packet assumes you are familiar with setting up the Arduino Serial
Console, and with using the Arduino Serial Console
The Arduino software provides several commands for reading values from the
Serial Console. Why so many? The answer is that “reading” input can mean
one of two things:
The simple input command: this just grabs input from the keyboard (or
whatever input device you are using), and then stores that input into some
location in memory.
The “fancy” input commands: these commands grab input from a device, then pick
out the value(s) of interest, and convert them from strings (since all keyboard input
is entered as plain text) to the data types of interest (which might be an integer,
a float, a String, or even a combination of these), and store them in memory.
There is only one “simple” input command,
Serial.read(), but there are
many “fancy” input commands, corresponding to many different types of input
the program might be looking for. Here are 3 of them:
- This command waits for input that “looks like” an integer (or until some preset timeout
- has passed) and then returns that input as a value of type
- This command waits for input that “looks like” a floating point number (or until some preset
- timeout has passed) and then returns that input as a value of type
- This command waits for input (until some preset timeout has passed) and then
- returns that input as a value of type
Examples of using these “fancy” commands will be demonstrated in this packet.
To learn more about the other
Serial input commands, refer to the Arduino
Language Reference on the
To learn how to use the simple, but fast
Serial.read() command was , refer to this
provided by user “Robin2” on the Arduino forum.