void SlowCooker::setup(){ pinMode(m_heaterRelayPin, OUTPUT); pinMode(m_lidSwitchPin, INPUT); setHeaterState(LOW); initTempSensor(); }
// run once in main loop, handles reading pin vals // setting heater on/off void SlowCooker::loop(){ m_lastLidState = m_lidState; m_lidState = digitalRead(m_lidSwitchPin); m_currentTemp = readTemp(); // float in C if(m_state == STATE_NOT_COOKING) return; if(calcHeaterState()){ if(!m_heaterActive){ Serial.println(F("Turning Heater On")); m_heaterOnTime = millis(); } setHeaterState(true); }else{ if(m_heaterActive){ Serial.println(F("Turning Heater Off")); m_heaterOnTime = millis(); } setHeaterState(false); } // check if cook is finished based on start time. // if cook time is zero then it will run forever!!! if(m_cookTime != 0){ long sLeft = (m_cookTime * 60) - ((millis() - m_timeCookStarted)/1000); if(sLeft <= 0){ stopCook(); m_eventCallback(EVENT_COOK_END); } } // send event if lid has been opened or closed. if(m_lastLidState && !m_lidState){ m_eventCallback(EVENT_LID_CLOSED); }else if(!m_lastLidState && m_lidState){ m_eventCallback(EVENT_LID_OPENED); } }
// stops cooking, resets counter. bool SlowCooker::stopCook() { m_state = STATE_NOT_COOKING; resetToDefault(); setHeaterState(LOW); }
/*** * Function: setHeaterOn(void) * Description: Turn heater on * Params: none * Returns: 0 if state was successfully written, 1 if not ***/ byte Si7020::setHeaterOn(void) { return setHeaterState(SI7020_HEATER_ON); }
/*** * Function: setHeaterOff(void) * Description: Turn heater off * Params: none * Returns: 0 if state was successfully written, 1 if not ***/ byte Si7020::setHeaterOff(void) { return setHeaterState(SI7020_HEATER_OFF); }