So I’m making a sketch that takes a two digit number from the usb port, checks the state of the pin that matches the number, then toggles the pin on/off.
For some reason, when I send 13 through the Arduino serial monitor, I get this message back: Pin number is greater than 14, details: 490 51 541
Meaning that the IDE is sending weird numbers, or the Arduino is processing them wrong. Do any of you see a problem as to why this isn’t working right?
If you enter the ASCII characters ‘1’ then ‘3’ then
Serial.read()will return 49 and 51. This is because in the ASCII character table ‘1’ and ‘3’ are represented by the numbers 49 and 51, respectively. If you want to find the number that the user typed out you have to convert it from ASCII.I’m not very familiar with the Arduino language, but assuming it’s similar to C you can find the changes needed Here.
I rewrote the program in another way, which may be clearer to Read.
The ‘0’ used in the source is simply another way of saying ‘the number used to represent the character ‘0”, so is 48. In C-like languages
'0' == 48,'1' == 49, etc, etc.