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