Difficulty compiling with a boolean function

I have a program that calls a boolean function. The function has an if statement in it that if I don't comment out I get a will not compile error with no reasonable explanation. "Error compiling for board Arduino Nano 33 BLE". I am trying to compile this for an Arduino Nano 33 BLE. I am compiling on a Windows 10 workstation.

The attached program will successfully compile if I comment out the "if" statement section as shown but then it comes back with a useless result. So I would like to understand why this is happening. I also included a few lines of the serial monitor with the if section commentated out.

Any help would be appreciated.
Thanks John

#include <ArduinoBLE.h>


void setup() 
{
    Serial.begin(115200);           
    while(!Serial);                         
    Serial.println(); Serial.print("************** SetUp() Complete ***********"); Serial.println(); Serial.println(); 
}

void loop()
{
  bool ShutOffEvent = TestBooleanEvent();          // Run status timed out event
  //bool ShutOffEvent = true

  Serial.print("ShutOffEvent = ");Serial.println(ShutOffEvent); Serial.println(); Serial.println();

}


bool TestBooleanEvent()
{
  static bool RunningEvent;                          // Fan running status
  static unsigned long AfterRunMillis;         // Time the key was sensed as being tuned off and after run stared
  unsigned long TimeOffMillis = millis();    // Current time
  const unsigned long RunTime = 50000;
  const int x = 0;

  Serial.println("This will only print with succesful complilation"); Serial.println();
  
  Serial.print("millis() = "); Serial.print(millis()); Serial.println();
  Serial.print("AfterRunMillis = "); Serial.print(AfterRunMillis); Serial.println();
  Serial.print("RunTime = "); Serial.print(RunTime); Serial.println();
  Serial.print("RunningEvent = "); Serial.print(RunningEvent); Serial.println();
  Serial.print("millis() - AfterRunMillis = "); Serial.print(millis() - AfterRunMillis); Serial.println();

/*
 /// This is the section that cause it not yo compile 
   if (millis()- AfterRunMillis > RunTime && RunningEvent)        // time event occured
 //if (x==0)                  // This doesent work either
  { 
    TimeOffMillis = 0                                            // TimeOffMillis reset to 0 
    Serial.println("********** RunStatusTimeOutEvent()Compleat**********"); Serial.println();
    return true;
  }
  /// End of bad section

  else
*/
  
  if (x==0)
   {
    AfterRunMillis = millis();                                    // Mark time of key off event Engine off fan running
    Serial.println("********** RunStatusTimeOutEvent()Compleat **********"); Serial.println();
    return false;      
  }
 
}

///// End of TestBooleeanEvent() ////////////////////////////////////////////////////////////

20:57:48.593 ->
20:57:48.593 -> ************** SetUp() Complete ***********
20:57:48.593 ->
20:57:48.593 -> This will only print with succesful complilation
20:57:48.593 ->
20:57:48.593 -> millis() = 5042
20:57:48.593 -> AfterRunMillis = 0
20:57:48.593 -> RunTime = 50000
20:57:48.593 -> RunningEvent = 0
20:57:48.593 -> millis() - AfterRunMillis = 5043
20:57:48.593 -> ********** RunStatusTimeOutEvent()Compleat **********
20:57:48.593 ->
20:57:48.593 -> ShutOffEvent = 0
20:57:48.593 ->
20:57:48.593 ->
20:57:48.593 -> This will only print with succesful complilation
20:57:48.593 ->
20:57:48.593 -> millis() = 5045
20:57:48.593 -> AfterRunMillis = 5043
20:57:48.593 -> RunTime = 50000
20:57:48.593 -> RunningEvent = 0
20:57:48.593 -> millis() - AfterRunMillis = 3
20:57:48.593 -> ********** RunStatusTimeOutEvent()Compleat **********
20:57:48.593 ->
20:57:48.593 -> ShutOffEvent = 0
20:57:48.593 ->
20:57:48.593 ->

Missing ; at the end of the statement.

Also:

1 Like

Thank you very much.

I actually did find that and was coming back to post. This caught be by surprise because I forget those ; all the time, but I usually get a syntax error telling me where the problem is. In this case it just came up as "Error compiling for board Arduino Nano 33 BLE". So I guess I cant rely on the compiler to watch my back on the ;.

Also the function is not well developed to do anything but demo the issue. The real function will be much more complex and will hopefully work. and just deliver a 1 or 0.

Thanks.
John

My advice would be to turn your default warning level up to "all". That's saved me from head scratching "why doesn't this work?" mistakes more times than I can count (and it correctly identified the missing ; in this case as well).

Thanks. I didn't even know there was such a setting. Just put it to all. I also did a search on the error "Error compiling for board Arduino Nano 33 BLE". It said it was caused by a bad board file and gave instructions to remove all the board files and reload them. That didn't work.

Thanks again.

1 Like