  */
 
 #include <DHT.h>
+#include <LiquidCrystal.h>
 #include "humidity.h"
 
 // used sensor type
 #define SENSOR_TYPE DHT22
+// timeout between readings
+#define SENSOR_TIMEOUT 2000
 
 // minimum temperature to operate
 #define MIN_TEMP 10
 
 // input pin for inside sensor
-#define SENSOR_INSIDE_PIN 5
+#define SENSOR_INSIDE_PIN 6
 // input pin for outside sensor
-#define SENSOR_OUTSIDE_PIN 6
+#define SENSOR_OUTSIDE_PIN 7
 // output pin for fan
 #define FAN_PIN 8
 

	float humidIn = absoluteHumidity(hIn, tIn);
	float humidOut = absoluteHumidity(hOut, tOut);

	int fanState = LOW;

	// simple state machine to provide easy extension and modification
	switch (state) {
		case STATE_IDLE:
			fanState = LOW;
			if (humidIn > humidOut && tOut > MIN_TEMP) {
				state = STATE_ACTIVE;
			}
			break;
		case STATE_ACTIVE:
			fanState = HIGH;
			if (humidIn <= humidOut || tOut <= MIN_TEMP) {
				state = STATE_IDLE;
			}
			break;
	}

	digitalWrite(FAN_PIN, fanState);


	Serial.print(humidIn);
	Serial.print(" | ");
	Serial.print(humidOut);
	Serial.print(" | ");
	Serial.println(state);

	delay(2000);
}


// inside sensor
DHT dhtIn(SENSOR_INSIDE_PIN, SENSOR_TYPE);
// outside
DHT dhtOut(SENSOR_OUTSIDE_PIN, SENSOR_TYPE);

// 2x16 display
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
	Serial.begin(9600);
	dhtIn.begin();
	dhtOut.begin();
	lcd.begin(16, 2);
	pinMode(FAN_PIN, OUTPUT);

	// Header for serial data	
	Serial.println("Humidity based fan control");
	Serial.println("Inside | Outside | State");
}
