What options are available for Spark automated rain barrel project?

Are you having a memory issue with your code?

can you explain what you are trying to do here in setup?

  int currentHour = Time.hour();

  // Don't operate at night if boolean off
  if (!UseNightTime) {
    if (currentHour > 21) {
      int tToMidnight = 24 - currentHour;
      Spark.sleep(SLEEP_MODE_DEEP, int ((tToMidnight + 6.8) * 60 * 60)); // want to wake up a few minutes before 7 so I don't sleep for 50 min again
    }
    if (currentHour > 7) {
      Spark.sleep(SLEEP_MODE_DEEP, int ((6.8 - currentHour) * 60 * 60)); // same thing, wait until morning a little before 7
    }
  }

it looks as if you are (providing the option of) selecting the ability avoid turning the system active when you powerup, I guess. Realizing that setup() only runs once, it is difficult to see what you want to do there.

FYI. Global variables (as you have created in the header) will permanently consume memory, whereas Local variables are released from the stack on a change of scope. So, keeping Global variables to a minimum is a good guideline for your programming.

Also these Global variables:

int useAutoIrrig = false ;
int useAutoValve = true;
int useDrainPump = false;
int useInletValve = false ;

each of these variables are reserving in the stack a four byte (32 bit) signed integer (int32_t) compared to something like this:

boolean useAutoIrrig = false ;
boolean useAutoValve = true;
boolean useDrainPump = false;
boolean useInletValve = false ;

which reserve the space for a single byte (8 bit) unsigned integer (uint8_t)

compacting your variables can help save memory... though in this example, it is not a huge amount!

I am not sure that this will give you what you want:

float minDist = 4 / 12;

since the right side is evaluated prior to the assignment. the expression (4/12) may be evaluated as an integer expression and could yeild the result of zero. However I am not sure if the compiler is smart enough to come up with your desired result which looks like you want it to be 0.33333.

you handled it correctly in other examples, and you can force the compiler to recognize that this is the division of floats by doing it this way:

float minDist = 4.0 / 12.0;
1 Like