3 interrupts...correct, the first and third are pretty simple. The middle one though, has floating point calcs
void IncrementFlowPulse () //This is the function that the flow sensor interrupt on pin 2 calls to add to the count and total count
{
//This function measures the rising and falling edge of the hall effect sensors signal
total_pulses++ ; //change to this variable so running tally is incremented in the background...
Count++;
tenth_gallon++; //be careful here, fuel_tenth and plural exist. this is used to decrement by tenth gallon once it is high enough
running=1;
}
// The setup() runs once, when the sketch starts
// the FOLLOWING loop() method runs over and over again,
// as long as the Arduino has power
//****************************************************************************************
void Repeats(){ //interrupt timer1 repeats every second-changed to 5 seconds...
//here is the math...we sample every 5 seconds. 9200 counts per gallon. FIXED-use float cast to convert integers to float before calculating
Calc = ((float)Count* ((float)720.0 / (float)k_factor)); //(Counts in 5 seconds/ number counts per gallon, converted from seconds to hours
//using a large value we can select any k-factor - use counts per gallon - perfect
// Calc is the gallons per hour.
if (!flag){ //reset flag so running total flag is run only once
flag=1;
} //this is used for averaging routine for average flow rate
if (Count>0){
stopped_flag++; //add 5 seconds to running time length
}
if (stopped_flag>5){ //this is to delay the time till we stop and wait....
//30 seconds or so...it decrements with no flow
stopped_flag=5; //add 5 seconds to length of time running, up to 30 seconds
//-each unit of increase = 5 seconds of stoppage
}
if (Count==0){ //decrement once per 5 second with zero flow...
stopped_flag--;
}
if (stopped_flag<=0){
stopped_flag=0; // no longer running
}
else {
running=1; //added this to ensure it stays running with flow
}
Count=0; //reset for next interrupt
//For some reason, when we start back up from stop, we re-enter the save routine.
if ((stopped_flag<=0) && (running) ){ //we were running, then stopped
state=10; //keeps returning to state 10, stop and save, and looping again
return;
}
}
//****************************************************************************************
void Toggle(){ //this is an interrupt to switch screens every few seconds
if (state==0){
state=1;
return;
}
if (state==1){
state=2;
return;
}
if (state==2){
state=0;
return;
}
}