The Mtobjects library
Event management for Uno, Nano, Mega
Download version V1.0.6
Version 1.0.2 (05/14/2025): Correction for compiler change, 2 files per objects
Version 1.0.3 (05/18/2025): Correction of the bug with delete, 2 files only
Version 1.0.4 (05/22/2025): Accelerations for stepper motors
Version 1.0.5 (05/22/2025): Bug correction for zero speed and for MTtimeBase
Version 1.0.6 (07/22/2025): Merge french version and English version
With a ZIP file: MTobjects.zip
With text files:
keywords.txt +
MTobjects.h +
MTobjects.cpp
The library
MTobjects is a tote library allowing event management for Uno, Nano, Mega cards (Minipro not tested). It eventually makes it possible to manage several tasks apparently independently of each other. You can do a lot of things even while the main program is working, including with delay()..
Most of the time, a program using MTobjets objects does not use loop. This allows you to easily run another program at the same time whether it is blocking or not. In addition, the library is initialized on its own, so there is no MTobjets.begin();. This frees the setup.
It completely uses Timer 0, which releases other timers for other applications. We can for example use the Servo library which needs a 16-bit timers. On the other hand, we cannot use analogwrite for the 5 and 6 pins of the Uno/Nano or 4 and 13 of the Mega because they use the timer 0.
The available objects are:
- MTclock: regularly calls a user action, for example for display or regular test of a value, for sending N inpulses to advance a stepper motor, to delay an action, or triggers an action after a certain time (timer)...
- MTdoubleClock: alternately calls two user actions, for example for the ignition and extinction of a fan, to run a servo once in one direction, once in the other
- MTbutton: manages a usual button, taking care of the rebounds. He calls a user function at each support. It can be used even during a delay().
- MTcheckButton: transform a push button in a genre two-way switch, a supported support, extinguished support..
- MTradioButton: transform a group of push button into a keyboard gender speed of a hood: support on one of them deactivates those of the group..
- MTsoftPWM: make PWM software, on all pins, but slowly (no more than 50khz). It's good to flash an LED, put an engine on the on/off cycle. If you want to go quickly without consuming resources, you will rather choose analogWrite() ou MThardPMW.
- MThardPWM: like analogWrite(), but by choosing its frequency better.
- MTservo: manage of Servo with 16-bit timers (few resources consumed). For soft management, there is the Servo library.
- MTservo4fils: same but with an additional thread which allows you not to move to initialization.
- MTulnStepper: manage stepper motors drived with a ULN2003. 10000 steps/s maxi by default.
- MTstepStepper: manage stepper motors with a driver using Step and Dir. 10000 steps/s maxi by default.
See also "Library setting" which can allow you to work faster or slower (for example, to run steps beyond 10,000 micro-steps/s, up to 41,000 micro-steps/s) or the MTsoftPWM beyond 5khz (up to 31khz).
It may be possible, to add objects or features to those that exist. But for that you have to talk to me. I can also help you use this library, I am very often on the french forum.
Priorities
MTobjects uses three layers of priority:
- internal management (memorization of support on the buttons, advances engines and servos
- event management (all user functions called during events)
- the content of setup() and loop()

Whether we do what we want, even with blocking code, that will not prevent engines or servos from moving, the buttons to be taken into
account.
A blocking code into loop() will be able to move a servo if you press a button or if a clock activates it.
If in the management of events, we have blocking code, it will block other functions as well as setup() or loop(), but does
not prevent the taking into account of the buttons. The other events will be activated at the end of the blocking code.
Used resources
MTobjects completely uses the timer 0. A 16-bit timer and the corresponding output is used by MThardPWM, by MTservo and by
MTservo4fils.
Two MThardPWM and/or MT???servo can use two different 16 bits (only on MEGA) or share the same timer. In the latter case, the frequency
must be the same!
Documentation
- Presentation and download
- Conventions
- The buttons
- Les horloges
- The PWM
- Les servos
- Stepper motors
- Library settings
- Some examples