We have looked at variables a little bit but now we are getting user input as Strings, we should go a little bit more into how they can be converted from one type to another.
Common Variable Types Used in Arduino
char | Character – A single letter, digit, etc |
byte | A number from 0-255 |
int | Integer – a number from -32,768 to 32,767 |
float | Floating point – a large number with a decimal point |
String | Textual content |
Strings can convert to integers using the built-in toInt() feature of the String object.
int nowANumber = myString.toInt();
As a demonstration, here is a sketch that accepts user input for Red, Geen and Blue values, and outputs the result as an RGB color.
