arduinoarduino-due

Serial.Read in the setup of an Arduino code?


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.


Solution

  • 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.