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:

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