Button logic

jointtech:
hey just removing all the delays and cleaning things up seems to have helped a bunch. my button presses seem to be recognized better now too. i dont have to hold the buttons down so long. still a little erratic ill keep working on it.
my checkflow function seems to be working again as well. :wink:
I removed all the delays except in the interupt. ill try removing that one next. I also fixed some places that were clearing the lcd and making it blink really fast.

There are a couple of things I can see in the code. But there is a larger issue that I will get to below.

First, you don't need to, and should not, use cli/sei. Don't Do That. There are only a few very special scenarios where you need to disable interrupts, and this isn't one of them.

Second, you could probably eliminate all the floating point operations by using a little algebra.
For example, a * 60 / 7.5 is equivalent to a * 120 / 15. There's more that can be done to completely convert to integer math, but I won't get into that here. For what you are doing, it probably works fine.

Also, the delay(1000) in checkflow is going to cause you some grief. During that 1 second
your sketch can't do anything else, like check the buttons. That may be OK in this case, but
it's going to slow down the response time. Do you want to wait 1 second to see the results of a button press? I myself would get impatient and maybe press the button again.
Instead of using a fixed delay, take a timestamp (millis()) and clear the NbTopsFan counter
during setup. Then when doing checkflow, you have the elapsed time and the counter value, and can calculate the rate. After doing the calculation, clear the counter and reset the timestamp, for the next time. One thing to watch out for is overflow of either millis or the counter. You can avoid that by resetting them both in loop() whenever they get too large.

However, the biggest issue that I see is that your buttons are not debounced. That means that in some cases you are going to press the button once, and it will act like it was pressed several times.
Fortunately for you, this is a problem that has been extensively studied and there are many solutions. Your task is going to be to integrate them into your sketch.
An excellent essay on debouncing can be found here Debouncing Contacts and Switches.
And there are libraries in the playground made for deboucing switches just like this.
Arduino Playground - HomePage
Arduino Playground - HomePage

Putting it all together... well that's the fun part.