This time, I designed two PLC mini-games using an 8×8 matrix:
- Whack-a-Mole
- Memory Sequence
Both games were developed using IEC 61131-3 Structured Control Language (SCL).
The purpose of these examples is not to “use PLCs to create games.” Instead, the goal is to help students learn SCL syntax, programming concepts, and problem-solving techniques through the game development process.
A. Why Learn SCL Through Games?
Most PLC beginners start with Ladder Diagram (LD), which is completely reasonable.
Advantages of LD:
- Similar to electrical circuits
- Well suited for Start/Stop control
- Ideal for latching, interlocking, and basic output logic
- Visual and easy to understand
However, when control requirements become more complex, such as:
- Matrix data
- Arrays
- Loops
- Level conditions
- Score tracking
- Time recording
- State machines
- Multi-condition decisions
the advantages of SCL become very apparent.
B. SCL and LD Are Not Competitors
One important concept demonstrated by these examples is:
SCL and LD are not competing languages, and neither one is intended to replace the other.
A better way to understand them is:
LD is suitable for:
- Contact logic
- Coil control
- Interlocking
- Latching
- Basic control circuits
SCL is suitable for:
- Data processing
- Arrays
- Loops
- State machines
- Complex conditions
- Algorithmic logic
What really matters is:
- Understanding the strengths of each language
- Choosing the right tool for the problem
- Avoiding reliance on only one programming style
- Not forcing every problem into the same language
C. What Can We Learn from Whack-a-Mole?
Although it looks like a game, it provides practice with many PLC techniques:
- 8×8 matrix input/output
- Byte data processing
- Bit masking
- Arrays
- FOR loops
- Random position generation
- Finite State Machines (FSM)
- Timer control
- Score tracking
- Level management
- Fastest time recording
- Current time measurement
- Short-press and long-press Reset functions
- Pause logic
These techniques can be directly applied to real industrial equipment.
D. What Can We Learn from Memory Sequence?
Memory Sequence focuses more on sequencing and data comparison.
Students can practice:
- Sequence generation
- Player input verification
- Array comparison
- Error detection
- Difficulty progression
- Target quantity management
- Reset functionality
- Pause control
- Game completion detection
These concepts correspond directly to:
- Sequential control
- Inspection processes
- Operator sequence verification
- Human-machine interaction workflows
- Equipment training simulators
- Mistake-proofing systems (Poka-Yoke)
E. Why Is an 8×8 Matrix Ideal for Teaching SCL?
An 8×8 matrix contains 64 points.
Using traditional methods, this might require:
- 64 inputs
- 64 outputs
- Large numbers of IF statements
- Long programs
- Difficult maintenance
Using SCL, however:
%IB0 ~ %IB7 represent eight input rows.
%QB0 ~ %QB7 represent eight output rows.
Each row is represented by a single Byte.
This enables:
- Array-based data management
- FOR-loop scanning
- Bit-mask operations
- Index-based positioning
- State-driven process control
This demonstrates the strength of SCL in data-oriented applications.
F. Industrial Applications Behind the Games
These techniques are not limited to games.
-
8×8 Matrix
Applications:
Indicator matrices, Keypad panels, Status displays -
Byte/Bit Processing
Applications:
I/O compression, Alarm code display, Bit-level data management -
Arrays
Applications:
Multi-station management, Multi-slot systems, Multi-workcell control -
FOR Loops
Applications:
Batch scanning, Data comparison, Channel verification -
State Machines
Applications:
Equipment workflows
Sequential control
Automatic cycles -
Timers
Applications:
Timeouts, Cycle timing, Long-press detection, Flashing indicators -
Score / Target
Applications:
Production quantities, Target counts, Completion tracking -
Fastest / Current Time
Applications:
Cycle time analysis, Best cycle performance, Efficiency monitoring -
Long-Press Reset
Applications:
Statistics reset, Maintenance functions, Special operation confirmation
G. What I Really Want Students to Learn
My goal is not to teach games.
I want students to learn:
- How to break requirements into processes
- How to convert processes into states
- How to manage I/O using data structures
- How to express timing conditions using timers
- How to reduce repetitive code with Arrays and FOR loops
- How to choose between LD and SCL appropriately
- How to move beyond programming and into control-system design
H. Conclusion
The 8×8 Whack-a-Mole and Memory Sequence projects are not merely PLC games.
They are SCL learning cases.
The key lessons are:
- LD is excellent for basic electrical control.
- SCL is excellent for data and process control.
- They are complementary, not competing technologies.
- Engineers should choose the most appropriate language based on the problem.
The purpose of learning SCL is not to replace LD.
It is to give PLC engineers another problem-solving tool.
As control requirements become more complex, SCL helps organize data, processes, conditions, and states more effectively.
That is the true value of learning SCL.
Regards
打地鼠_記憶遊戲.factoryio (169.9 KB)
