Hi, Im struggling with this I got a temperature dependable program,to make complete bulletproof I need to re-start this machine each time is called, but just execute it once. I cant find a way to acomplish this.
This is the machine:
void refrigerationOFF(){
/*
This subrutine is intended to start the refrigeration cycle
in a ladder way to prevent high current spikes on the lines
making the start easier by the release of the pressurized
refrigerant.
*/
// boolean refrigerattionOFFHasEnd = false;
if(refrigerattionOFFHasEnd == false ) // if the refrigerattion has no ended properly
{ // re-statrt the FSM
Serial.println("Se ha reinciado la maquina de refrigeracion OFF");
pascomOff = 0;
compOff = 0;
refrigerattionOFF = true; //enable the statrt of the FSM
refrigerattionOFFHasEnd = true; //this var make refrigeration once
}
if ( refrigerattionOFF == true ) //if there is the first time this is called
{
if( millis()- comOffTime >= comOffDelay) //take delay for each operation on FSTM
{
compOff ++;
comOffTime = millis();
}
if(compOff > pascomOff )
{
switch(compOff)
{
case 1:
lcd.setCursor(0,0); lcd.print(F(" FIN DE "));
lcd.setCursor(0,1); lcd.print(F(" REFRIGERACION "));
lcd.setCursor(0,2); lcd.print(F(" "));
break;
case 2:
lcd.setCursor(0,0); lcd.print(F("FIN DE REFRIGERACION"));
lcd.setCursor(0,1); lcd.print(F(" APAGANDO "));
lcd.setCursor(0,2); lcd.print(F(" COMPRESOR "));
digitalWrite(compressor, HIGH);
break;
case 3:
lcd.setCursor(0,0); lcd.print(F("FIN DE REFRIGERACION"));
lcd.setCursor(0,1); lcd.print(F(" APAGANDO "));
lcd.setCursor(0,2); lcd.print(F(" VENT"));
for( int c = 0; c < NumFans ; c++)
{
digitalWrite(fanPins[c], HIGH);
lcd.setCursor(13,2); lcd.print(c);
}
break;
case 5:
lcd.setCursor(0,0); lcd.print(F("FIN DE REFRIGERACION"));
lcd.setCursor(0,1); lcd.print(F(" APAGANDO "));
lcd.setCursor(0,2); lcd.print(F(" SOLENOIDE "));
digitalWrite(solenoid, HIGH);
break;
case 6:
lcd.setCursor(0,0); lcd.print(F(" "));
lcd.setCursor(0,1); lcd.print(F(" "));
lcd.setCursor(0,2); lcd.print(F(" "));
refrigerattionOFF = false; //this var make refrigeration once
compOff = 0; //byte to control the switch case statment
pascomOff = 0;
//refrigerattionOFFHasEnd = true; //this cheks if the FSM has ended properly
break;
}
}
}
}
This is the thermostat that call the subrutine:
if( temperature == highTemp)
{
refrigerationON();
Now... if for any reason (like error in the sensor reading) all will be off by;
if(rawTemp < -30.00) // if the sensor dont read
{
temperature = error ;
stopAll();
How to make the machine start over each time is called and just the firs time is called?
Ii was trying to use a local variable;
// boolean refrigerattionOFFHasEnd = false;
if(refrigerattionOFFHasEnd == false ) // if the refrigerattion has no ended properly
{ // re-statrt the FSM
Serial.println("Se ha reinciado la maquina de refrigeracion OFF");
pascomOff = 0;
compOff = 0;
refrigerattionOFF = true; //enable the statrt of the FSM
refrigerattionOFFHasEnd = true; //this var make refrigeration once
}
But dint work... each loop gets 0 and never executes the machine.
If I declare the same variable as global, there is no warranty the machine complete its task and get ready to next time.
I dont know the proper name but I need something like this;
void loop()
{//Pseudocode
if(temperature == high) refriON(); //this will be called many times
}
refriON()
{
startrefri { //clears all the variables to the machine works properly each time the machine is called
but just do it for one time during the machine is runnign...}
It has to be local, for work each time the machine is called. Clear all the variables and prevent miss functions.
I was using a variable at the end of the switch case, but in errors the switch case will be interrupted and It wont be re-inicialized.
Is there a Way to call this... One time only during each start of the machine?
if(refrigerattionOFFHasEnd == false ) // if the refrigerattion has no ended properly
{ // re-statrt the FSM
Serial.println("Se ha reinciado la maquina de refrigeracion OFF");
pascomOff = 0;
compOff = 0;
refrigerattionOFF = true; //enable the statrt of the FSM
refrigerattionOFFHasEnd = true; //this var make refrigeration once
}
Just once but each time the machine has start... this is the last part and its getting omplicated.
Thanks.
-Alex.