When I use the line "Serial.read()" I would like the variable that I send, that it is used as, for instance, when I send "4", that the arduino doesn't use the 52th key, but the number 4.
Could anyone help me out?
this is my code:
/* By inserting 1 variable in the Serial monitor, I should get the table of that number
Hey foitn
I am a beginner and also strugling with the serial communication
Try change the line "char incomingbyte = Serial.read();" to " char incomingbyte = Serial.read()-'0';
I think it should work
Welcome to the Forum! Several things:
First, please make sure you read the first two posts on this Forum by Nick Gammon. It tells you the proper way to post your code and following those instructions will generate more help for you.
Second, PaulS raises a good question about the use of a for loop. If the Serial.read() method only returns a single character, it doesn't help to print it out 20 times.
Third, he also points out that "magic numbers" in code (e.g., your 48) tend to be forgotten over time and makes your code harder to read at some later date. There are a number of ways to avoid them, such as:
#define ASCIIZERO 48 // Place this line before setup()
// ... more of your code...
int answer = (incomingbyte - ASCIIZERO) * i;
Another way is to use a constant:
const int ASCIIZERO = 48; // Place this line before setup()
// ... more of your code...
int answer = (incomingbyte - ASCIIZERO) * i;
Finally, before you post your code, click in the source code window of the IDE, press Ctrl-T, and the IDE will format your code into a common C style. (If your code can't be compiled, Ctrl-T won't work.)