 // PWM  *****************************************************************
 
 // initialize the timer1 interrupt for the frequency variable output
- Timer3.initialize(33333);                   // initialize timer1, and set a 33.333ms period -> 30Hz
+// Timer3.initialize(33333);                   // initialize timer1, and set a 33.333ms period -> 30Hz
  
 //   Timer3.pwm(RELAIS_HEATER, pwmDuty);     // setup pwm on pin 9, 50% duty cycle
 


static stm_substate_t         stm_SubState;
static stm_substate_time_t    stm_time_SubState;



// Private function prototypes ***********************************************


//analogRead(RELAIS_HEATER);

LowerLevelHeater = getTemperatureOvenSetPoint()-3;
HigherLevelHeater = getTemperatureOvenSetPoint()+3;

 //if (timerSet && timerOver) {
   //  stop the function completely
  // }
if (runSmoker == 0) {
  
   if ((getTemperatureOven() >= (getTemperatureOvenSetPoint()+5)) || (getTemperatureMeat() >= getTemperatureMeatSetPoint()))
          {

                          #ifdef DEBUG
                          Serial.println(F("Pulsed signal and heater stop"));
                          #endif
  
           // Timer3.disablePwm(RELAIS_HEATER);
            digitalWrite(RELAIS_HEATER, LOW);
            displayCommandSmall1("Heater off");
            digitalWrite(RED_LED_PIN, HIGH);
            digitalWrite(GREEN_LED_PIN, LOW);
            ovenState = false;
          }
      else if(LowerLevelHeater <= getTemperatureOven())     
         {             

                          #ifdef DEBUG
                          Serial.println(F("Pulsed signal"));
                          #endif


                currentMillisHeater = millis();

                if ((currentMillisHeater - previousMillisHeater) >= intervalHighHeater) {     
                   if (ovenState) {
                          #ifdef DEBUG
                          Serial.println(F("heater stop"));
                          #endif
                          
                         digitalWrite(RELAIS_HEATER, LOW);
                         displayCommandSmall1("Heater Low 1m");
                         digitalWrite(RED_LED_PIN, LOW);
                         previousMillisHeater = currentMillisHeater;
                         ovenState = false;
                  } 
                  else if ((currentMillisHeater - previousMillisHeater) >= intervalLowHeater) {

                          #ifdef DEBUG
                          Serial.println(F("heater on"));
                          #endif
                          
                          digitalWrite(RELAIS_HEATER, HIGH);
                          displayCommandSmall1("Heater High 30s");
                          digitalWrite(RED_LED_PIN, HIGH);
                          previousMillisHeater = currentMillisHeater;
                          ovenState = true; 
                  }
              } 

            
           
        } 
          else if((getTemperatureOven() <= getTemperatureOvenSetPoint()-4))
            { 
                          digitalWrite(RELAIS_HEATER, HIGH);
                           ovenState = true;
                           
                          #ifdef DEBUG
                          Serial.println(F("LED BLink heat up"));
                          #endif
                          displayCommandSmall1("Heating up");
                          
                          digitalWrite(GREEN_LED_PIN, HIGH);
                          delay (1000);
                          
                          digitalWrite(GREEN_LED_PIN, LOW);
                          delay (1000);  
            } 


}



if (getSmokerState() == TRUE)
{
 //displayCommandSmall2("Smoker aktive");
 currentMillisSmoker= millis();
  
        if (getTemperatureOven() >= getTemperatureOvenSetPoint()-2) {
            if (runSmoker == 0) {
              displayCommandSmall2("Smoker run");
              previousMillisSmoker = currentMillisSmoker;
              smokerCounter = 0;
              smokerState = true;
              digitalWrite(RELAIS_HEATER, LOW);
              digitalWrite(RELAIS_SMOKER, HIGH);
              ovenState = false;
            }
            runSmoker = 1;

        }
        if((runSmoker == 1) && (smokerCounter < 3)) {
                if (((currentMillisSmoker - previousMillisSmoker) >= intervalHighSmoker)) {     
                         if(smokerState == true) {
                          #ifdef DEBUG
                          Serial.println(F("Smoker stop"));
                          #endif
                          
                         digitalWrite(RELAIS_SMOKER, LOW);
                         displayCommandSmall2("Smoker Low 2m");
                         digitalWrite(RED_LED_PIN, HIGH);
                         previousMillisSmoker = currentMillisSmoker;
                         smokerState = false;
                         smokerCounter = smokerCounter + 1;
                         }
                       if (((currentMillisSmoker - previousMillisSmoker) >= intervalLowSmoker)) {
                          if (smokerState == false) {
                            #ifdef DEBUG
                            Serial.println(F("Smoker on"));
                            #endif

                            digitalWrite(RELAIS_HEATER, LOW);
                            digitalWrite(RELAIS_SMOKER, HIGH);
                            ovenState = false;
                            displayCommandSmall2("Somker High 30s");
                            //digitalWrite(RED_LED_PIN, HIGH);
                            previousMillisSmoker = currentMillisSmoker;
                            smokerState = true; 
                          }
                  }
                }
                  if (smokerState == FALSE) {
                        if ((getTemperatureOven() >= getTemperatureOvenSetPoint()+5) || (getTemperatureMeat() >= getTemperatureMeatSetPoint()))
                        {

                          #ifdef DEBUG
                          Serial.println(F("Pulsed signal and heater stop"));
                          #endif
  
     
                          digitalWrite(RELAIS_HEATER, LOW);
                     
            
                         digitalWrite(RED_LED_PIN, HIGH);
                         digitalWrite(GREEN_LED_PIN, LOW);
                          ovenState = false;
                         }
                     
      else if(LowerLevelHeater <= getTemperatureOven())     
         {              
                          #ifdef DEBUG
                          Serial.println(F("Pulsed signal"));
                          #endif


                currentMillisHeater = millis();

                if ((currentMillisHeater - previousMillisHeater) >= intervalHighHeater) {     
                   if (ovenState) {
                          #ifdef DEBUG
                          Serial.println(F("heater stop"));
                          #endif
                          
                         digitalWrite(RELAIS_HEATER, LOW);
                         displayCommandSmall1("Heater Low 1min");
                         digitalWrite(RED_LED_PIN, LOW);
                         previousMillisHeater = currentMillisHeater;
                         ovenState = false;
                  } 
                  else if ((currentMillisHeater - previousMillisHeater) >= intervalLowHeater) {

                          #ifdef DEBUG
                          Serial.println(F("heater on"));
                          #endif
                          
                          digitalWrite(RELAIS_HEATER, HIGH);
                          displayCommandSmall1("Heater High 30s");
                         // digitalWrite(RED_LED_PIN, HIGH);
                          previousMillisHeater = currentMillisHeater;
                          ovenState = true; 
                  }
              } 

            
           digitalWrite(GREEN_LED_PIN, HIGH);
           digitalWrite(RED_LED_PIN, LOW);
           
        }  
   else if((getTemperatureOven() <= getTemperatureOvenSetPoint()-4))
   { 
     digitalWrite(RELAIS_HEATER, HIGH);
      ovenState = true;
                          #ifdef DEBUG
                          Serial.println(F(" heating up"));
                          #endif
                          displayCommandSmall1("Heating up");
           
                          
                          digitalWrite(GREEN_LED_PIN, HIGH);
                          delay (1000);
