MTD2A is a collection of user friendly advanced and functional C++ classes - building blocks - for time-controlled handling of input and output. The library is intended for Arduino enthusiasts without much programming experience, who are interested in electronics control and automation, and model trains as a hobby.
• Build on a state machine system for parallel processing and synchronous timing
• Support a wide range of input sensors and output devices
• Are simple to use to build complex solutions with few commands
• Operate non-blocking, process-oriented and time controlled
• Offers extensive control and troubleshooting information
• Thoroughly documented with examples
Code, documentation and examples
MTD2A is a so-called state machine. This means MTD2A objects are quickly traversed in an infinite loop, and each traversal is divided into two phases:
- Changing state variables (changing and/or reading and checking)
- Execute functionality and control the passage of time.
The top
The lower MTD2A_loop_execute(); and as the last in void loop();
In this way, an approximate parallelization is achieved, where several functions can in practice be executed simultaneously. For example, two flashing LEDs, where one is synchronous and the other is asynchronous. Example of parallel processing https://youtu.be/eyGRazX9Bko
The MTD2A library can be mixed with custom code and other libraries without further ado, as long as the execution is done non-blocking. But it requires a slightly different mindset when developing code, as it must always be taken into account that the infinite and fast loop must not be delayed, but also that user code is not executed more times than what is intended. It is often necessary to use different types of logic control flags.
It is absolutely crucial that no delaying or blocking code is used with the MTD2A library. Do not use delaying functions such as delay(); as well as bibliographies that prevent rapid passages of the infinite loop. However, by default, delays up to a maximum of 10 milliseconds are allowed per pass. In most cases, this is sufficient of time to execute custom code and different types of libraries simultaneously. See further explanation MTD2A_englsh.pdf
Further explanation: Finite-state machine - Wikipedia and here: Real-time operating system - Wikipedia
https://github.com/MTD2A/MTD2A/tree/main/doc
https://makeabilitylab.github.io/physcomp/
MTD2A is part of the official Arduino library, and can be downloaded directly from the Arduino IDE (Integrated Development Environment) via the Library Manager

