You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So even though there is no call in loop(), SerialEvent() will indeed be called when there is data available.
What is not correct is this statement on that page:
This function is called inside the loop().
I believe that is the cause of the confusion, and should be fixed.
My suggested edit to the page:
Change:
This example demonstrates use of the SerialEvent() function. This function is called inside the loop(). If there is serial data in the buffer each character found is added to a string until a newline is found.
To:
This example demonstrates use of the SerialEvent() function. This function is called when there is Serial data available. Each received character is added to a string until a newline is found.
This example demonstrates use of the SerialEvent() function.
Once having been initialized by an arbitrary function
void serialEvent() { ... }
this function is called then automatically in the background when there is Serial data available. Notice that there is no need to call this function then repeatedly in the loop() function.
Each received character is added to a string until a newline is found.
PS,
IMO that is a bad practice though, one would expect to initialize a function or class in setup(), additionally specifying the arbitrary Serial port, like e.g.,
This tutorial:
https://www.arduino.cc/en/Tutorial/SerialEvent
for SerialEvent()
is missing a call to SerialEvent()
in the loop() function. The code is never called.
The text was updated successfully, but these errors were encountered: