boolean function -no return needed

hi all,

This is probably a silly question, but I don't have an arduino at the moment nearby but I'm already writing a sketch which I'll need next week.

I have made a function boolean CheckAcknowledge() that waits for a serial acknowledge to check if a command is correctly executed. It will return 'true' when the acknowledge is correctly returned and false if it's not (response indicating that the command was not executed). If there is no response at all, it will timeout after 5 seconds, flag a global variable to mark this, and return a false.

Now my question: can I call this function -somewhere- without minding the response? I would like to use this function at some point just to flag the global variable, but I don't care whether it returns true or false. So, could I just call:

CheckAcknowledge();

or should it always be something like:

boolean response = CheckAcknowledge();

Thanks a lot for the response!

You can safely ignore the return value. Both notations are correct.

Thanks! Bedankt!

You should make it clear that you know that you're ignoring the return value (void) CheckCondition();

okay, I'm unfamiliar with this notation. :) What does this '(void)' exactly do? Is this just good practice so the next programmer knows you're ignoring the value? Or are you telling the compiler something with this statement?

Thanks!

jensvanhoof: okay, I'm unfamiliar with this notation. :) What does this '(void)' exactly do? Is this just good practice so the next programmer knows you're ignoring the value? Or are you telling the compiler something with this statement?

The former. The compiler doesn't care.

I have made a function boolean CheckAcknowledge() that waits for a serial acknowledge to check if a command is correctly executed. It will return ‘true’ when the acknowledge is correctly returned and false if it’s not (response indicating that the command was not executed). If there is no response at all, it will timeout after 5 seconds, flag a global variable to mark this, and return a false.

The signature of the function seems incorrect to me as there are three possible values
ACK_RECEIVED, NAK_RECEIVED, TIMEOUT,

so you could define a returntype

enum ComState { ACK, NACK ,TIMEOUT };

ComState CheckAcknowledge()
{
   start = millis();
   while (millis() - start < 10000)  // 10000 is the timeout in millisecs
   {
    if (Serial.Available() > 0)
    {
      int c = Serial.Read();
      if (c == ???) return ComState.ACK;
      if (c == ???) return ComState.NACK;
      // other chars are ignored in this example
    }
   }.
  return ComState.TIMEOUT;
}

so you could define a returntype

Except that the no acknowledge value is generally abbreviated NAK.

ACK