Selecting which pulse comes first to Arduino

I am using 4 push buttons ,four shift registers and four seven segment displays. My project is to for a garment factory.There are four sewing lines. When a sewing line doesn’t have cut fabric they should inform it to the cutting department.Here I need to select who wanted cut fabric first,who wants it second,thirdly and who wants cut fabric at last . I am using push buttons to press when they want cut fabric. A seven segment display is allocated for one button.Likewise there are four seven segment displays for four push buttons.If a button is pressed firstly it should show number 1 on the display.If a button is pressed secondly it should display number 2 on the attached display to pushbutton. My intention is to prioritize push button presses.

My code runs OK if one button is pressed at one time.If two or more buttons have been pressed it shows the same number on every display.

Can anybody suggest me a way to prioritize signal inputs.

four_bttn_shiftedssd.ino (15.1 KB)

If you don't factor your code now, fixes and improvements such as you are asking for will be very difficult, and are going to become exponentially more difficult as you proceed. With that many I/O's doing tightly related and almost identical tasks, you need to use arrays to simplify and generalize the logic. Otherwise you will quickly run out of memory and patience. Your fingers might even fall off from all the typing.

I agree 100% with @aarg. Re-organizing your code MUST have a higher priority than sorting out the problem behind your question. If a business is to rely on the program then it must be written so it can be debugged and maintained easily.

Indeed if you re-organize your code it will be so much simpler that you may find the solution as a by-product.

Have a look at how the code is organized in Planning and Implementing a Program and also learn about arrays.

...R