Skip to content

readTiming()

Arnd edited this page Apr 20, 2017 · 1 revision

readTiming(Index,onTime,offTime);

This function will return the last time that the device went from an ON to an OFF state as "offtime" and the last time that the device went from OFF to ON as "onTime". The values are in the Arduino's millis() units. The function returns a boolean TRUE if the values have changed since the last time that readTiming() was called.


Example:

CubigelClass Cubigel(&Serial1);// Instantiate with fridge on HW1 //

...

void loop() {
  delay(10000); // wait 10 seconds
  uint32_t onTime,offTime;
  bool changed = Cubigel.readTiming(0,onTime,offTime);
  if (changed) {
     if (onTime>offTime) {
        Serial.print("Compressor 0 turned ON after being off for ");
        Serial.print((onTime-offTime)/1000);
     } else {
        Serial.print("Compressor 0 turned OFF after being on for ");
        Serial.print((offTime-onTime)/1000);
     }
     Serial.println(" seconds.");
  } of if-then value has changed
} // of main loop
Clone this wiki locally