hi.
i have 2 question.
-why there is a "L" after 2000 in Serial.setTimeout(20000L) ;
- and How much should be written in parentheses? cuz i 'm gettin timeout error in my serial monitor.
hi.
i have 2 question.
-why there is a "L" after 2000 in Serial.setTimeout(20000L) ;
'L' means, in this context, a long (32 bit) signed integer. The 20000 or 2000 is in milliseconds.
See Stream.setTimeout() - Arduino Reference
IMHO you would be better writing non-blocking code that is not held up waiting for a timeout.
Have a look at the examples in Serial Input Basics - simple reliable non-blocking ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.
...R
1. The syntax is:
long t = 2000; //range of t:-2147483648 to 2147483647; allowable range: 0 to 2147483647
Serial.setTimeout(t); //t is in milliseconds and can not be negative
2. The above two lines could be written in the following compact form:
Serial.setTimeout(2000L); //2000 has the data type (L for long and not Long) and meaning as stated in Step-1