#include "chiller.h"
#include <EEPROM.h>
int thermistorPin = 0;
int peltierPin = 1;
Chiller chiller;
struct Setting{
float targetTemp;
float threshold;
bool autoHeating;
} setting;
void setup() {
Serial.begin(115200);
Serial.println("Initializing...");
loadConfig();
chiller.init(peltierPin, thermistorPin);
chiller.setTargetTemp(setting.targetTemp,setting.threshold,setting.autoHeating);
Serial.println("Ready");
saveConfig();
}
void loop() {
chiller.run();
Serial.print("Temperature: ");
Serial.print(chiller.getCurrentTemp());
Serial.println(" C");
Serial.print("Target: ");
Serial.print(chiller.getTargetTemp());
Serial.println(" C");
Serial.print("Threshold: ");
Serial.print(setting.threshold);
Serial.println(" C");
Serial.print("Auto Heating: ");
Serial.println(setting.autoHeating);
Serial.print("Status: ");
Serial.println(chiller.getStatus());
Serial.print("Mode: ");
Serial.println(chiller.getMode());
delay(1000);
}
void loadConfig() {
Serial.println("Loading configuration");
EEPROM.begin(1024);
byte sig = EEPROM.read(0);
EEPROM.get(1, setting);
EEPROM.commit();
EEPROM.end();
if(sig != 1){
Serial.println("First run");
setting.targetTemp = 26;
setting.autoHeating = true;
setting.threshold = 1;
}
Serial.println("Loaded");
}
void saveConfig() {
EEPROM.begin(1024);
EEPROM.put(0, byte(1));
EEPROM.put(1, setting);
EEPROM.commit();
EEPROM.end();
}