mirror of
https://bitbucket.org/myhomie/mycorerepository.git
synced 2025-12-06 01:31:19 +00:00
143 lines
3.4 KiB
C++
143 lines
3.4 KiB
C++
#include <Adafruit_GFX.h>
|
|
#include <Adafruit_SSD1306.h>
|
|
#include <OneWire.h>
|
|
#include <DallasTemperature.h>
|
|
|
|
// Data wire is plugged into port 2 on the Arduino
|
|
#define ONE_WIRE_BUS 2
|
|
OneWire oneWire(ONE_WIRE_BUS); // (a 4.7K resistor is necessary)
|
|
DallasTemperature sensors(&oneWire);
|
|
DeviceAddress Thermometer; // variable to hold device addresses
|
|
int deviceCount = 0;
|
|
// Addresses of 2 DS18B20s
|
|
// uint8_t sensor1[8] = { 0x28, 0x08, 0x46, 0xF8, 0x62, 0x20, 0x01, 0xD2 }; // OLD
|
|
// uint8_t sensor2[8] = { 0x28, 0x1A, 0x59, 0xF3, 0x62, 0x20, 0x01, 0x60 }; // OLD
|
|
uint8_t boiler[8] = { 0x28, 0x63, 0x92, 0xF3, 0x62, 0x20, 0x01, 0x3C }; // BOILER
|
|
uint8_t panneaux[8] = { 0x28, 0x7F, 0x38, 0x01, 0x63, 0x20, 0x01, 0x49 }; // OLD
|
|
|
|
#define OLED_RESET 4
|
|
Adafruit_SSD1306 display(OLED_RESET);
|
|
|
|
#define NUMFLAKES 10
|
|
#define XPOS 0
|
|
#define YPOS 1
|
|
#define DELTAY 2
|
|
|
|
#define LOGO16_GLCD_HEIGHT 16
|
|
#define LOGO16_GLCD_WIDTH 16
|
|
static const unsigned char PROGMEM logo16_glcd_bmp[] =
|
|
{ B00000000, B11000000,
|
|
B00000001, B11000000,
|
|
B00000001, B11000000,
|
|
B00000011, B11100000,
|
|
B11110011, B11100000,
|
|
B11111110, B11111000,
|
|
B01111110, B11111111,
|
|
B00110011, B10011111,
|
|
B00011111, B11111100,
|
|
B00001101, B01110000,
|
|
B00011011, B10100000,
|
|
B00111111, B11100000,
|
|
B00111111, B11110000,
|
|
B01111100, B11110000,
|
|
B01110000, B01110000,
|
|
B00000000, B00110000 };
|
|
|
|
#if (SSD1306_LCDHEIGHT != 32)
|
|
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
|
|
#endif
|
|
|
|
const int Led = 9;
|
|
|
|
const int Relay = 4;
|
|
|
|
const int diffDegree = 3;
|
|
|
|
long waitTime = 60000;
|
|
long TimeRequestMillis;
|
|
|
|
char* relaystate = "Close";
|
|
|
|
bool lock = false;
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
Serial.println("-----------------");
|
|
Serial.println("");
|
|
Serial.println("Initialisation...");
|
|
Serial.println("");
|
|
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
|
|
display.display();
|
|
delay(2000);
|
|
|
|
// Clear the buffer.
|
|
display.clearDisplay();
|
|
|
|
pinMode(Relay, OUTPUT);
|
|
digitalWrite(Relay, LOW);
|
|
|
|
TimeRequestMillis = millis();
|
|
}
|
|
|
|
|
|
void loop() {
|
|
|
|
sensors.requestTemperatures();
|
|
|
|
unsigned long currentMillis = millis();
|
|
|
|
Serial.print("temperature_Panneaux - ");
|
|
float temperature_Panneaux = getTemperature(panneaux);
|
|
|
|
Serial.print("temperature_Boiler - ");
|
|
float temperature_Boiler = getTemperature(boiler);
|
|
|
|
if(lock == false){
|
|
|
|
if((temperature_Panneaux > temperature_Boiler + diffDegree) && (lock == false)){
|
|
digitalWrite(Relay, HIGH);
|
|
relaystate = "Open";
|
|
Serial.println("Relay Open");
|
|
}
|
|
else{
|
|
digitalWrite(Relay, LOW);
|
|
relaystate = "Close";
|
|
Serial.println("Relay Close");
|
|
}
|
|
Serial.println("Lock");
|
|
lock = true;
|
|
}
|
|
|
|
if(currentMillis - TimeRequestMillis > waitTime){
|
|
TimeRequestMillis = currentMillis;
|
|
Serial.println("Unlocked !");
|
|
lock = false;
|
|
}
|
|
|
|
// text display values
|
|
display.setTextSize(1);
|
|
display.setTextColor(WHITE);
|
|
display.setCursor(0,0);
|
|
display.print("Panneaux: ");
|
|
display.print(temperature_Panneaux);
|
|
display.println("C");
|
|
display.print("Boiler: ");
|
|
display.print(temperature_Boiler);
|
|
display.println("C");
|
|
display.print("Statut relay : ");
|
|
display.println(relaystate);
|
|
display.display();
|
|
delay(2000); //mettre plus ! ;)
|
|
display.clearDisplay();
|
|
|
|
}
|
|
|
|
float getTemperature(DeviceAddress deviceAddress)
|
|
{
|
|
float tempC = sensors.getTempC(deviceAddress);
|
|
Serial.print(tempC);
|
|
Serial.print("C");
|
|
Serial.println();
|
|
return tempC;
|
|
}
|