/*
We need your help to stop forest fires and bake tasty cookies!
See `requirements.md` for how to help.
Then check `notes.md`.
//TODO implement the 5 second timer for IGNITER
*/
#include "api.h"
void setup() {
Serial.begin(115200);
setup_api();
Serial.println("Elf oven 2000 starting up.");
serial_printf("Days without fire incident: %i\n", 0);
}
void door_sensor_interrupt_handler(bool voltage_high)
{
while(digitalRead(3) == HIGH){
set_output(IGNITER, false);
set_output(GAS_VALVE, false);
}
}
void loop() {
if(digitalRead(3) == HIGH){
door_sensor_interrupt_handler(true);
}
int16_t sensor_voltage = read_voltage(TEMPERATURE_SENSOR);
int16_t sensor_vref = read_voltage(TEMPERATURE_SENSOR_REFERENCE); //added vref millivolt variable
int temp_real;
int voltPer = sensor_voltage/50;
if(voltPer < 10 || voltPer > 90 ){ //checking if voltPer is within temp spec of sensor
temp_real = 0; //set to 0 instead of ?????
}else{
temp_real = -10 + (3.875 * (voltPer-10)); //calculating temp from voltPer
}
int16_t temp_vref = (sensor_vref-500)/10; //calculating vref temp from millvolts
serial_printf("sensor_voltage %i\n", sensor_voltage);
serial_printf("sensor_vref %i\n", sensor_vref); //printing vref millivolt
serial_printf("temp_real %i\n", temp_real); //printing real temp in centigrade
serial_printf("temp_vref %i\n", temp_vref); //printing vref temp in centigrade
if(temp_real < 180){
set_output (IGNITER, true);
set_output (GAS_VALVE, true);
} else if (temp_real > 185){
set_output (GAS_VALVE, false);
set_output (IGNITER, false);
}
delay(500); //lowered iteration period to allow for 5 second delay in IGNITER turning off
}