2019-04-14 23:11:37 +02:00

129 lines
2.7 KiB
C++

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#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(115200);
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() {
unsigned long currentMillis = millis();
int valeur_brute = analogRead(A0);
float temperature_Panneaux = valeur_brute * (5.0 / 1023.0 * 100.0);
//Serial.println("LM35 : "+temperature_celcius); *0.63652437
//Serial.print("Temperature LM35: ");
//Serial.println(temperature_Panneaux);
int valeur_brute2 = analogRead(A1);
float temperature_Boiler = valeur_brute2 * (5.0 / 1023.0 * 100.0);
//Serial.print("Temperature2 LM35: ");
//Serial.println(temperature_Boiler);
if(lock == false){
if((temperature_Panneaux > temperature_Boiler + diffDegree) && (lock == false)){ //mettre plus diff de degré
digitalWrite(Relay, HIGH);
relaystate = "Open";
}
else{
digitalWrite(Relay, LOW);
relaystate = "Close";
}
Serial.println("Lock");
lock = true;
}
if(currentMillis - TimeRequestMillis > waitTime){
TimeRequestMillis = currentMillis;
Serial.println("Unlocked !");
lock = false;
}
// text display tests
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();
}