// bibliothikes
#include <OneWire.h> // gia thermokrasia
#include <DallasTemperature.h> // gia thermokrasia ???
#include <Wire.h> // gia othoni me analogiko
#include <LiquidCrystal_I2C.h> // gia othoni me analogiko
#include <DHT.h> //gia ygrasia
//int backLight = 13; // gia to ledaki tou ardouino!!! adiaforo!!
int led = 9;
int ledh = 7;
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3
#define DHTPIN 6 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = HIGH; // ledState used to set the LED
boolean flagoff=true;
boolean flagon=false;
unsigned long currentMillis=0;
unsigned long previousMillis=0;
boolean timetostopflag=false;
int buttonState = 0;
const int buttonPin = 2;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x38,16,2); // set the LCD address to 0x20 for a 16 chars and 2 line display
DeviceAddress Temp1address = { 0x28, 0xB8, 0x3F, 0x8E, 0x04, 0x00, 0x00, 0x01 }; //diefthinsh gia thermokrasia
DeviceAddress Temp2address = { 0x28, 0x7E, 0x35, 0x8E, 0x04, 0x00, 0x00, 0x91 }; //diefthinsh gia thermokrasia
DeviceAddress Temp3address = { 0x28, 0x31, 0xC4, 0x8E, 0x04, 0x00, 0x00, 0xAB }; //diefthinsh gia thermokrasia
DeviceAddress Temp4address = { 0x28, 0x5D, 0xA0, 0xD1, 0x03, 0x00, 0x00, 0x23 }; //diefthinsh gia thermokrasia
void setup(void)
{
// start serial port
//Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(Temp1address, 10);
sensors.setResolution(Temp2address, 10);
sensors.setResolution(Temp3address, 10);
sensors.setResolution(Temp4address, 10);
lcd.init(); // initialize the lcd
lcd.backlight(); //afth h grami einai gia to fos ths othonis
//lcd.print("Hello, aaaaworld!"); // afth h entolh einai pou sou emfanizi to minima sthn othoni
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void tImeon(long svist ){
if(flagoff==true){
if(currentMillis - previousMillis > svist) {
//if (ledState == HIGH){
// ledState = LOW;
//previousMillis = currentMillis;
// flagon=true;
//flagoff=false;
timetostopflag=true;
}
}
}
void tImeoff(long anamen){
if(flagon==true){
if(currentMillis - previousMillis > anamen) {
if (ledState == LOW){
ledState = HIGH;
previousMillis = currentMillis;
flagoff=true;
flagon=false;
timetostopflag=false;
}
}
}
}
void TwoSensorRange(float sensorA,float sensorB, float minA ,float maxB)
{
if (sensorA <= minA )
digitalWrite(led, HIGH);
if (sensorB >= maxB )
digitalWrite(led, LOW);
}
void StaticSensor(float tSensor , float s,int pIn)
{
if ( tSensor <= s )
digitalWrite(pIn, HIGH);
else
digitalWrite(pIn, LOW);
}
void StaticSensorMinus(float tSensor , float s,int pIn)
{
if ( tSensor < s )
digitalWrite(pIn, HIGH);
else
digitalWrite(pIn, LOW);
}
void SensorRange(float SensorOnoff, float Min, float Max ,int pIn)
{
if ((SensorOnoff<=Min) && (SensorOnoff<=Max))
digitalWrite(pIn,HIGH);
if ((SensorOnoff >= Max ) && (SensorOnoff >= Min))
digitalWrite(pIn, LOW);
}
void printTemperature(float tempC , int x , int y )
{
//float tempf = DallasTemperature::toFahrenheit(tempC);
//float h = dht.readHumidity();
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
//Serial.print("C: ");
//Serial.print(tempC);
//Serial.print(" ,, ");
//lcd.clear();
lcd.setCursor(x,y); //me afto tou les pou tha grapsi thn epomenh fora me thn epomenh entolh!
lcd.print(tempC);
lcd.setCursor(x+4,y);
lcd.print(" ");
}
}
void printHumidity(float h , int x, int y)
{
//Serial.print("Hum: ");
//Serial.print(h);
//Serial.print(" ,, ");
//lcd.clear();
lcd.setCursor(x,y); //me afto tou les pou tha grapsi thn epomenh fora me thn epomenh entolh!
lcd.print(h);
lcd.setCursor(x+4,y);
lcd.print(" ");
}
void All(float s1,float s2,float s3,float s4,float Min ,float Max)
{
if ((s1<=Min) || (s2<=Min) || (s3<=Min) || (s4<=Min))
digitalWrite(led,HIGH);
if ((s1>=Max) || (s2>=Max) || (s3>=Max) || (s4>=Max))
digitalWrite(led,LOW);
}
void loop(void)
{
//digitalWrite(13, LOW);
//delay(250);
//digitalWrite(13, HIGH);
//delay(250);
currentMillis = millis();
buttonState = digitalRead(buttonPin);
tImeoff(60*1000);
tImeon(9*60*1000);
if (timetostopflag==true && (buttonState==HIGH)){
if (ledState == HIGH){
ledState = LOW;
previousMillis = currentMillis;
flagon=true;
flagoff=false;
}
}
digitalWrite(ledPin, ledState);
//Serial.print("Getting temperatures...\n\r");
sensors.requestTemperatures();
//Serial.print("start temperature ");
float T1=sensors.getTempC(Temp1address);
float T2=sensors.getTempC(Temp2address);
float T3=sensors.getTempC(Temp3address);
float T4=sensors.getTempC(Temp4address);
printTemperature(T1,0,0);
printTemperature(T2,5,0);
printTemperature(T3,0,1);
printTemperature(T4,5,1);
float h=dht.readHumidity();
printHumidity(h,11,1);
//SensorRange(h,70.00,71.00,7); // arithmos epistrofis sensora , min , max , pin
StaticSensor(T3,37.50,7);
StaticSensorMinus(T1,37.75,9);
//TwoSensorRange(T3,T4,37.25,37.75);
//All(T1,T2,T3,T4,37.50,38.00) ;
// SensorRange(T4,37.4,37.6,7);
//SensorRange(T1,37.4,37.6,9);
//Serial.print("\n\r\n\r");
}