Can Productivity 2000 shift 8 button presses through an array?

Brian Holt9 min read
AutomationDirectHMI ProgrammingTechnical Reference
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

A rolling 8-entry button history on a Productivity 2000 (P2000) CPU is one Shift Rotate Array (SRA) instruction on an 8-element integer array, not a FIFO. Each press loads a numeric code into the inflow position, the oldest entry falls out the other end, and the win condition is an element-by-element compare against a preset array. The wrong turns below cost the most time on this job, so they come first.

Skip the FIFO instruction for a rolling window

The P2000 FIFO instruction is a queue with separate push, pop, and peek operations, and a rolling window needs all three coordinated on every press once the queue is full. Push adds at the tail. Pop removes from the head. Peek reads without removing. To keep the last 8 entries you would test for full, pop the oldest, push the new value, then peek at each position to compare against the combination. That is why the instruction reads as overly complex for this job.

The requirement is a fixed-length sliding window: entering "ABABCDCB" and then pressing button 4 must yield "BABCDCBD". An array shift does the drop-oldest and insert-newest in one instruction and leaves every position readable by index, which the compare needs.

Keep the copy-and-move rungs only as a temporary restore

Discrete copy and math rungs that move data register to register work on P2000 and are backward compatible with Click, but they cost rungs. The existing programs carry roughly 40 rungs of copy and math that one SRA rung and one Array Statistics (STA) rung replace.

  • Temporary restore: if the room is running tonight, leave the working copy/move logic in place and build the array version in a saved copy of the project.
  • Permanent repair: move to arrays on P2000. Use copy/move rungs only for the Click version, where arrays do not exist.

Do not shift characters in a string array

SRA does not support string arrays, so storing "A" through "D" as strings and shifting them fails or is rejected. Store numeric codes in the array and convert to characters only for display.

  1. Assign each button an integer code (button 1 = 1, button 2 = 2, and so on).
  2. Shift and compare the integers.
  3. Present them as A, B, C, D on the player-facing side.

The number-to-string conversion is the CPC instruction, and the numeric source must itself be an array element. Plan for that when you lay out the tags.

Treat the register as a one-dimensional array of 8 integers

An array is a block of same-datatype storage addressed by index, and no special logic sits behind it. On P2000 an array has one or two dimensions, read like spreadsheet columns and rows.

Form Addressing Use here
1D array ArrayName(column) The 8-press history. Element 1 holds the oldest press, element 8 the newest.
2D array ArrayName(row),(column) Not needed for a single combination.

Every single item is a one-element array, so nothing changes conceptually when you widen it to 8. The array-aware instructions that matter here:

Instruction Role in this job
Shift/Rotate Array (SRA) Moves the history one position per button press.
Copy Array Copies the entered combination into the preset array during a reprogram step.
Fill Array Clears or seeds the history.
Array Statistics (STA) Analyzes array contents. Read its help page for the statistics it offers before you use it for the compare.

Resize the tag SRA creates before you trust any result

An SRA that throws error messages on a tag the software created for you is the signature of a 1x1 array tag. The software does not arbitrarily create arrays. When you accept the instruction as finished, it prompts you to create a tag for every name in a field that does not resolve to an existing tag, and the default is a single element.

  1. Open the tag database and find the array tag, for example ARRAY_Button_Panel_Combo_Entered.
  2. Set the array size to 8 elements in one dimension.
  3. Set the datatype to an integer type wide enough for your largest button code.
  4. Apply the same size and datatype to the preset array (ARRAY_Button_Panel_Preset_Combo) and to any outflow tag, such as DATA_Button_Panel_Outflow, so the fields stay type-compatible with the instruction.
  5. Re-open the SRA and confirm every field resolves without an error.

Shift one position per button press

Drive the SRA from a single rising-edge trigger so each press moves the window exactly once, and load the inflow value before the shift executes in the same scan. The shift on every scan is the most common failure of a first attempt: without an edge, the button code fills all 8 positions within 8 scans.

  1. Give each button its own rung that loads the inflow tag with that button's numeric code on the press edge.
  2. Fire the SRA once per press from a common "any button pressed" edge placed after the load rungs. This also handles two buttons landing in the same scan without a double shift.
  3. Set the shift direction so the oldest entry ends up in element 1 and the newest enters at element 8. Confirm the direction option in the SRA dialog by watching the array in the data view on the first press.
  4. Route the outflow (the value pushed out of element 1) to DATA_Button_Panel_Outflow if you need it. The win logic does not need it.

A count-based alternative fills by index and then shifts. Use it only when the game needs to know how many presses occurred.

Design Behavior Win condition fit
Always shift (sliding window) Every press enters at element 8 and pushes the rest toward element 1. Matches the requirement: 100 presses of button 1 followed by 1 through 8 still wins.
Count, then shift Presses 1 to 8 copy into the array at index = press count. Presses 9 to 16 use the press as an SRA trigger. Beyond 16 you must ignore or reset. Needs a reset policy. The count-limit contact is a limit compare with count <= 8 on the copy rung and count > 8 on the SRA rung.

The requirement has no reset based on presses, so the always-shift design fits and needs no counter. The count-based design would break the stated 100-presses case at press 17 unless you add a reset.

Compare the two arrays with eight equal contacts

The compare stops being hard once you stop looking for a whole-array compare and test each position. Put eight equal-to contacts in series on one rung, one per element pair, and drive the win coil from the rung.

|-[ Entered(1) = Preset(1) ]-[ Entered(2) = Preset(2) ]- ... -[ Entered(8) = Preset(8) ]-( WIN )-|

Series contacts give an AND across all eight positions, so a single mismatch drops the rung. This form is also portable: on Click the same eight compares read eight data registers instead of array elements.

  • Compare the entered array only against the preset array, never against a literal string.
  • Copy Array moves the current combination into the preset array during the reprogram step. That part already works; the compare consumes its result unchanged.
  • Put the win compare after the SRA in scan order so it evaluates the just-shifted array on the same scan.

Go past 10 buttons by keeping integers in the array

The 10-button ceiling comes from the character approach, not from the array. A character-per-button scheme holds one symbol per position, so a code of 10 or more needs two digits and no longer fits one position. The integer array has no such limit.

  1. Store button codes 1 to N as integers in the shift array. Integer compares are exact for any N your datatype can hold.
  2. Do the compare on the integers, as in the previous section.
  3. For the player display, convert with CPC from an array element to a string, or map each code to a lookup character on the display side.

The integer array carries the two-digit values as single elements, which lets you go past the ten buttons of the character version.

Emulate the array on Click with plain copies

Click has no arrays, so the shift becomes a chain of copy instructions on consecutive data registers. Write the rungs so each source register is read before it is overwritten.

Rung A (press edge): Copy R2 -> R1
Rung B (press edge): Copy R3 -> R2
...
Rung G (press edge): Copy R8 -> R7
Rung H (press edge): Copy Inflow -> R8

Scan order runs top to bottom, so shifting from the oldest end first preserves every value. Reverse the order and every register ends up holding the newest value. Use a single one-shot for all eight rungs, load Inflow first, and finish with the eight-contact compare against eight preset registers. This is the same approach the old 40-rung programs already use, so it stays compatible with the Click version.

Bench-test the window before it goes back in the room

Test with the array open in the data view, not just the win output. Codes: A = 1, B = 2, C = 3, D = 4.

Action Expected array after the action
Press 1, 2, 1, 2, 3, 4, 3, 2 1, 2, 1, 2, 3, 4, 3, 2 (ABABCDCB)
Then press 4 2, 1, 2, 3, 4, 3, 2, 4 (BABCDCBD), oldest entry gone
Hold one button for many scans Exactly one shift per press
Press button 1 100 times, then 1, 2, 3, 4, 5, 6, 7, 8 against preset 1 through 8 WIN on the eighth press of the sequence
One wrong entry inside an otherwise correct 8 No win, and the rung drops at the mismatched element

If the array shows the wrong length or the SRA faults on the first press, go back to the tag database and recheck the array size and datatype, then the shift direction.

FAQ

What happens if a player presses the same button 100 times before the real code?

With the always-shift design the history keeps only the last 8 presses, so the 100 early presses are pushed out and the win rung sees only the final 8 entries. The count-based design would run past 16 presses and needs its own reset or ignore logic.

What happens if I try to shift a string array with SRA?

Shift/Rotate Array does not support string arrays, so the instruction will not accept that tag. Store numeric codes in an integer array, shift and compare those, and convert to characters with CPC only for display.

What happens if SRA still throws errors after the tags are resized?

Stop after you have confirmed the array is 8 elements, the datatype matches the instruction's fields, and the trigger is a single edge. Then contact AutomationDirect technical support through their official support channel with the project file and the exact error text. Do not keep rebuilding tags on a running machine.

Back to blog