I have 10 Hoppers each with 2 level sensors; one is at the 75% full level and the other is at the 25% full level.
I need to fill hoppers that fall below the 25% level (High Priority) first, then any that fall below the 75% level (Normal Priority).
That is all the information that seat14 has given us.
Clearly, there are only 2 sensors per hopper, and filling does not mean fill from under low level to high level in one go, but merely prioritize the hoppers that are below low level, then the hoppers that are between low and high, and then the hoppers that are over high level.
I do it in this way:
First there is a master clock that initiates a hopper change, for example every 30 seconds. I dont want the hopper switch over happens too often just because some sensor switches a little too often.
When the master clock says "change now", the next hopper is found this way: First filtering out the hoppers that are unavailable for filling, i.e. the operator has set the hopper to "do not fill", or there is an issue with some device associated with the hopper, i.e. sensor discrepancy or hardware used for the filling.
On the remaining hoppers, I then check if there is any available hopper below low level, and if so select a subsequent hopper in series after the active hopper.
If there is no hopper below low level, I check if there is any hopper between low and high level, and if so select a subsequent hopper in series after the active hopper.
If there is no hopper below high level, I check if there are any available hoppers, and if so select a subsequent hopper in series after the active hopper.
I create an alarm if there are no available hoppers at all.
I create a warning if all available hoppers are above high level for a longer time.
I create a warning if all available hoppers are below low level for a longer time.
The operator cannot select all hoppers to 'do not fill'. There must be at least one available hopper.
The program uses an array for representing the hoppers. The code uses the index to circulate from 1st to last and back to 1st again.
It becomes more complex if you also have to switch over without 'spilling'. If for example you switch from hopper 1 to 3 and no spillage may fall in hopper 2.
I cannot post my code, it is the property of my company, but the actual coding is not such a big deal. It is the precise description of what the code must do that is important. When you have done that the code almost writes itself.
edit: I see that seat14 probably do not want to fill unless at least there is a hopper that is below high level.
In that case, the filling shall stop when there is no available hopper, but the state shall be remembered by the code, so that the filling sequence starts from the same state when hopper(s) becomes available again.
In my case the hoppers are used as a storage of material that is in perpetual circulation, and I cannot interrupt the filling.