Is it possible to perform a Serial.Read in the Setup area of an Arduino code? I need my main loop to be fast and don't want it to be slowed down by a piece of code that only has to run once.
Asked
Active
Viewed 1,369 times
2 Answers
1

HallMark
- 101
- 9
-
1I cannot see the answer to Lego man's question in that link. BTW, the answer is 'possible, but not useful'. You need a loop anyway to wait for any incoming text after Serial.begin() ( and eventually another loop ** while (!Serial() ) {} ** ) For loops, you best use the predeclared loop() function. – datafiddler Aug 06 '16 at 12:43
1
You can put Serial.read() in the setup() function. Be sure that you put it after Serial.begin(). Since Serial.read() is "non-blocking" you will need to put some additional code to loop and wait for something to read. Serial.read() returns -1 if there is no data waiting in the serial input buffer.

tddguru
- 392
- 1
- 4