Go Down

Topic: serialEvent with yes/no dialogue? (Read 960 times) previous topic - next topic



serialEvent works perfectly as advertised. For the moment I use it with the Arduino terminal as I havn't started to link that to Processing.

Many times, you'd like your sketch to return an acopalyptic message requiring confirmation of a command. For example, if you type:

apocalypse <send>

Arduino could reply:

Delete Earth, Solar system, Galaxy, Universe; or Wait another day (E/S/G/U/W)?

It should be easy enough to program (presumably using static variables) but, since this is a commonly-required action, does anyone have a library that does the job in the professional manner?


It should be easy enough to program (presumably using static variables)

With a finite state machine, sure it wouldn't be difficult at all to program.


Keep in mind that serialEvent is only called when there is serial data to be processed, and the end of loop is reached.

It does not get called so the Arduino can send a message, nor is there anything about it that causes a wait for a reply.
The art of getting good answers lies in asking good questions.


@PaulS : then what I'm asking for would be an additional library.

For those of us new to this sort of thing, the logic behind serialEvent is hard to follow. As it's built in to Arduino, the user doesn't see whether or not 'void serialEvent()' is an interrupt handler that's called any time data arrives. Is the the following part of the comment before void serialEvent() in the example a little bit misleading?

'This routine is run between each time loop() runs,...

If it is an interrupt handler, should the reader just be advised to get back into loop() as frequently as necessary?  In my case they are typed in the terminal and can wait a few seconds for action.


It isn't interrupt driven. It is called after each iteration of loop(), in main.cpp, which the Arduino IDE adds to your sketch:

Code: [Select]
#include <Arduino.h>

int main(void)

#if defined(USBCON)

for (;;) {
if (serialEventRun) serialEventRun();
return 0;

Go Up