Code a menu that won't interfere with process

I'm putting together the hardware for an industrial batch process that will use the Uno, some relays, RTC, SD, and I am planning on using Adafruit's I2C LCD w/ 5-buttons LCD Shield Kit w/ 16x2 Character Display - Only 2 pins used! [BLUE AND WHITE] : ID 772 : $19.95 : Adafruit Industries, Unique & fun DIY electronics and kits.

Before I go ahead with the purchase, I just want to make sure that the software will work properly. I'll paste the pseudo code below of what I want the batch process to do, but my issue is that there are 3 variables (x, y, and z) that I want to change without connecting it to a computer, but I want to make sure that I can do this without interrupting the process below.

Cycle - 8 hrs (repeats 3 x per day)
Turn on Pump1
Wait x seconds/Measure current
Turn off Pump1
Check Switch state
If Switch is up, turn on pump2 for y min while measuring current
If Switch is down, turn on pump2 on for 1 min/measure current
Wait t-y min (if switch is up) or t-1 min (if switch is down)
Repeat previous lines 5 times
Wait 2 hours
While Switch is up, turn on Pump3
Measure current, measure time until Switch falls
Write info to SD card and EEPROM
Align time start cycle 8 hrs after last cycle

If at any time during the pumps running, current is > z amps, turn off pump and sound alarm.

While this is running, I want the capability to enter a menu to change x, y, and z and to read some info stored in the EEPROM, again without interrupting the cycle.

So I want to accomplish 3 things - 1) The batch cycle, 2) constant monitoring of amps w/ alarm and 3) enter the menu.

Any tips on how to keep these things from interfering with each other?

Thanks!

Seems you are thinking in seconds for timing.
Arduino is very much faster than that.
You will have plenty of time and interfaces for what you want to do.
But you will have to use more variables than what you're probably thinking of now.
I don't see any problem for an Arduino to do what you like it to do, but an Arduino is not an industrial device.
If you really meant industrial as in it will be deployed in some fabrication plant, check regulations for that.

Something more to consider for you:
There's a lot of waiting or pausing in your plan.
Pausing is doing nothing but counting time.
You can also do a lot like checking someone is pressing menu keys and display the LCD contents while you are checking time has passed and you need to switch something.
You can have the display displaying x y and z all the time and use those 5 keys to navigate through them and alter their values.

Check some of the examples and have a look at "blink without delay", the sketch that is referred to a million times already on this forum.

Read a lot on this forum and you'll see what else you need (because you need a bit more than the UNO and the LCD keypad shield.
Also, the keypad also has a reset button real close to the other keys and it's not hard to press that by accident.
I'd remove it before really using your setup.

Thanks for the reply!

I intend to use millis in general for the timing, as they do in the tutorial, and was thinking of doing either 1 or 3 (1 for each cycle) Alarm.alarmRepeat based on the RTC to keep more accurate time (I really like the fact that MicroChip's MCP79412 logs power outages, so will probably go with that instead of the DS1307).

Since there is a lot of waiting, should I just create a loop, called checkButtons, that checks each button as well as the amp meter repeatedly and run it under a 'while' command, something like this:

while(currentMillis - previousMillis < interval)
checkButtons()

If this is right so far, would I then need to do this at each waiting step, or is there someway to make this global throughout the program? Is there a general type of interrupt code that can be inserted once and will bring up the menu at any point? Once I get into the menu, I can piece together how to handle it from other examples.

As for the industrial side, I am just prototyping on Arduino. Once I have the hardware worked out, I am printing a board and getting it UL stamped. I am thinking of selling a version of the hardware with the UL-stamp so others can offer UL approved products. I haven't found any UL-listed Arduinos, so maybe this could fill a need.

Thanks again for your help so far.

Once I have the hardware worked out, I am printing a board and getting it UL stamped.

Have you any idea how much that is going to cost you? Have you done a UL approval before? No only does your circuit have to be approved but the factory where you make it has to be approved., and that entailes visits every 3 to 6 months to check you are keeping up the approval. So UL costs you about £2000 plus about £600 a year on going. You have to sell a lot of boards to cover that.

called checkButtons, that checks each button as well as the amp meter repeatedly and run it under a 'while' command, something like this:

while(currentMillis - previousMillis < interval)
checkButtons()

If this is right so far,

No that is not the way to do it. In the loop function always check the buttons and use the currentMillis - previousMillis < interval to control when you do the processes.

I have a menu in a project. I was concerned with someone starting to change something and then leaving it. Leaving the sketch sitting waiting for input. The way I dealt with it is to have a time out on my menu. Generally where I'm checking for button presses I also check to see if the menu time out has come and make it exit. One of my buttons also exits so it was the same behaviour on a time out. Also, every time a button is pressed or the pot is rotated the time out timer gets reset. It's only with inactivity that it will time out and quit.

Basically I have a global variable where I store the time of an activity like a button press. So that if the current time - the time out length is > last activity time then exit the menu and resume normal operation.

I also like to put time out timers in while loops. I remember the first time I type while() into an Arduino sketch I was struck by how they could be a serious problem if the exit conditions are never met.

Guess what void.loop does.

If you use a while loop, you're looping within a loop.
Why would you want to do that.
Just check to see if someone is pressing a key and what that means.
See if a timer has ended and if an input tells you you have to change some state.
Do what you just registered.

After that, void.loop will start over again unless you do something to prevent that (by leaving that loop or entering an other unconditional loop).

For debugging, you can try to have void.loop run once and measure how much time that takes.
You should do multiple measurements as not all runs will take the same amount of time.

Thanks for the replies!

So I did some more digging and found the the attachInterrupt() command can be used with the hardware interrupt pins on the Uno (it has two). I guess I will have to wire a button directly to that pin rather using one of the buttons over I2C. One tutorial I found says to include "volatile int state = LOW;" before the setup, which will store the state in RAM making it less likely to be inaccessible during the sketch. http://www.dave-auld.net/index.php?option=com_content&view=article&id=107:arduino-interrupts&catid=53:arduino-input-output-basics&Itemid=107

So that solves having to write the 'loop within the loop'. The issue that is left is how to set up the menu so that it doesn't interrupt the process.

So that if the current time - the time out length is > last activity time then exit the menu and resume normal operation.

This could be problematic for me, since there is one pump that should only run 3 seconds, so even if I do a 5 sec timeout, the pump will run too long if someone enters the menu while the pump is on.

I remember the first time I type while() into an Arduino sketch I was struck by how they could be a serious problem if the exit conditions are never met.

This is my fear...since timing is critical to this process, things have to happen as close to a set schedule as possible.

Have you any idea how much that is going to cost you? Have you done a UL approval before?

I have worked with UL, but is the first time as a PCB designer. I have a quote from sunstone.com for $200 to proof a board and then they will give it a UL stamp. I then have to use all UL recognized parts on the PCB. I've already talked to a local machine shop that will do final assembly in the panel and can put a UL label on it...I just have to meet with their UL inspector before the first run. My cost will be higher per unit, but I can postpone paying the thousands of $$$ until I'm selling thousands of boards. XD

The issue that is left is how to set up the menu so that it doesn't interrupt the process.

You use a software construct called a finite state machine. This is where a state variable controls how far into the menu process you go. In that way you don't get stuck waiting for a button press.
There is no need to use interrupts, in fact using interrupts is not the way to go at all. This is because you still have to do something with the interrupt signal and you can't spend very long in an interrupt service routine.

An example of this sort of state machine was used in this project of mine:-
http://www.thebox.myzen.co.uk/Hardware/Dice_Game.html
You can download the software.
The "close the lid" switch is constantly monitored, then the state machine sees which part of the game is being played, does that function and then returns / ends the loop function. This applies especially for the situations where you are waiting for user input.
So in your case each traverse of the loop would look like:-
check state machine -> level 0 waiting for button if you see button change state to level 1
check pumps for on / off time -> switch pumps and set next time to change them
end loop

check state machine -> level 1 update menu display, change to level 2 waiting for user input
check pumps for on / off time -> switch pumps and set next time to change them
end loop

check state machine -> level 2 get user input only update to level 3 when you have user input ...
check pumps for on / off time -> switch pumps and set next time to change them
end loop

...... and so on

but I can postpone paying the thousands of $$$ until I'm selling thousands of boards

You must live in the U.S.A. because UL inspectors try everything in their power to make things impossible for people outside the country. I see it as a form of protectionist unofficial import control.