#include "api.h"
#define HighTemp 3750 //250 °C
#define Thresh 0.1
#define TempTreshH 2750 // ~ 183 °C
#define TempTreshL 2650 // ~ 177 °C
#define TempNormal 2700 //180 °C
#define IgniterInterval 1700 // ~ 5 sec
//Red LED shows the status of the "oven" -> ON: Oven is on // OFF: Oven is off
//Green LED shows the status of the "door" -> ON: door is open // OFF: door is closed
//Blue LED shows the status of the "valve" -> ON: Valve is Open // OFF: Valve is close
//Yellow LED shows the status of the "igniter" -> ON: Igniter is on // OFF: Igniter is off
unsigned int DangerousTemp = 0;
unsigned long Cnt = 0;
void setup() {
Serial.begin(115200);
setup_api();
Serial.println("Elf oven 2000 starting up.");
serial_printf("Days without fire incident: %i\n", 0);
}
void loop() {
while(read_voltage(DOOR_SENSOR)<=90 && !DangerousTemp){
if(read_voltage(TEMPERATURE_SENSOR)>=HighTemp)
DangerousTemp = 1;
if(read_voltage(TEMPERATURE_SENSOR)<TempTreshL){
set_output(GAS_VALVE, HIGH);
set_output(IGNITER, HIGH);
if(Cnt<IgniterInterval)
Cnt++;
else
set_output(IGNITER, LOW);
}
if(read_voltage(TEMPERATURE_SENSOR)>TempTreshH){
set_output(GAS_VALVE, LOW);
set_output(IGNITER, LOW);
Cnt=0;
}
set_output(Oven, HIGH);
set_output(Door, LOW);
serial_printf("sensor_voltage %i\n", read_voltage(TEMPERATURE_SENSOR));
}
if(DangerousTemp){ // Keep the Oven off while the Temp is higher than max mean
set_output(Oven, LOW);
set_output(GAS_VALVE, LOW);
set_output(IGNITER, LOW);
Cnt=0;
}
if(read_voltage(TEMPERATURE_SENSOR)<=(HighTemp - (HighTemp*Thresh))) // Check if Temp has dropped under max figure
DangerousTemp = 0 ; // and turn the oven on if Temp is in the right range
if(read_voltage(DOOR_SENSOR)>90){ // Check if the door was opened -- Deactive all parts in this situation
set_output(Oven, LOW);
set_output(Door, HIGH);
set_output(GAS_VALVE, LOW);
set_output(IGNITER, LOW);
Cnt=0;
}
else
set_output(Door, LOW); // If the door was closed, let the oven comes back to its normal operation
serial_printf("sensor_voltage %i\n", read_voltage(TEMPERATURE_SENSOR));
delay(1000);
}