PaulS:
If you take AWOL's advice to move the pin reading/average calculation code into a function, you would call it like so:void loop()
{
float voltage = readVoltage(PHOS_IN_A1);
if( voltage <= 2000 ) //If voltage less than 2V
{
digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
}
else if( voltage > 2000 ) //If voltage more than 2V
{
digitalWrite(DEP_TIME, LOW) ; //Gives no output if no gasses are flowing
}
voltage = readVoltage(BOR_IN_A2);
if( voltage <= 2000 ) //If voltage less than 2V
{
digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
}
else if( voltage > 2000 ) //If voltage more than 2V
{
digitalWrite(DEP_TIME, LOW) ; //Gives no output if no gasses are flowing
}
voltage = readVoltage(ARS_IN_A3);
if( voltage <= 2000 ) //If voltage less than 2V
{
digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
}
else if( voltage > 2000 ) //If voltage more than 2V
{
digitalWrite(DEP_TIME, LOW) ; //Gives no output if no gasses are flowing
}
}
which clearly would be a problem, as the timer would be turned on if a gas was flowing, and off if the last gas was not flowing. So, you fix that by adding a flag:void loop()
{
bool gasIsFlowing = false;
float voltage = readVoltage(PHOS_IN_A1);
if( voltage <= 2000 ) //If voltage less than 2V
gasIsFlowing = true;
voltage = readVoltage(BOR_IN_A2);
if( voltage <= 2000 ) //If voltage less than 2V
gasIsFlowing = true;
voltage = readVoltage(ARS_IN_A3);
if( voltage <= 2000 ) //If voltage less than 2V
gasIsFlowing = true;
// If gas is flowing, turn on the timer
if(gasIsFlowing)
{
digitalWrite(DEP_TIME, HIGH); //Gives 5V output to dep timer
}
else
{
digitalWrite(DEP_TIME, LOW) ; //Gives no output if no gasses are flowing
}
}
Cheers Paul. I was just editing my reply as you did this and that is how I was thinking. I have never declared a flag before so I was a bit unsure of where it went etc. I was just digging through my notes while I tried to see what you meant, but it was making sense what I had to do