 
 // Forward declarations
 DH22Reading readDH22 ();
+void updateState (ControlledValue &variable);
 void getCurrentRuntime (int &days, int &hours, int &minutes, int &seconds);
 void updateAverages (float temp, float humidity);
 void printTime ();

    _numWraparounds = 0;
    _runtimeInSeconds = 0;
    _lastCheckTime = 0;
    _lastTempStateChangeTime = 0;
    _lastHumidityStateChangeTime = 0;
    _tempState = STATE_OFF;
    _humidityState = STATE_OFF;
    
    for (int i = 0; i < 60; ++i) {
      _tempsLastHour[i] = 0;

  int check;
};

enum State {
  NOT_CONTROLLING,
  CONTROLLING_UP,
  CONTROLLING_DOWN
};

struct ControlledValue {
  float current;
  float target;
  float tolerance;
  int pinToIncrease;
  int pinToDecrease;
  uint32_t lastStateChangeTime; // In **seconds**, not milliseconds!
  State state;
};

ControlledValue temperature = {0, TEMP_TARGET, TEMP_TOLERANCE, 10, 9, 0, NOT_CONTROLLING };
ControlledValue humidity = {0, HUMIDITY_TARGET, HUMIDITY_TOLERANCE, 11, 12, 0, NOT_CONTROLLING };

uint32_t _lastCheckTime;

unsigned long _numWraparounds; // How many times has the clock wrapped
unsigned long _runtimeInSeconds; // 4 bytes, so a max of 4,294,967,295 (something like 136 years)
