The tmr module allows access to simple timers. It is aimed at setting up regularly occurring tasks and timing out operations.
What the tmr module is *not* however, is a time keeping module. While all timeouts are expressed in milliseconds, the accuracy is limited and compounding errors would lead to rather inaccurate time keeping. Consider using the [rtctime](rtctime.md) module for "wall clock" time.
This is a convenience function combining [`tmr.obj:register()`](#tmrobjregister) and [`tmr.obj:start()`](#tmrobjstart) into a single call.
To free up the resources with this timer when done using it, call [`tmr.obj:unregister()`](#tmrobjunregister) on it. For one-shot timers this is not necessary, unless they were stopped before they expired.
#### Syntax
`mytmr:alarm(interval_ms, mode, func())`
#### Parameters
-`interval_ms` timer interval in milliseconds. Maximum value is 6870947 (1:54:30.947).
-`mode` timer mode:
-`tmr.ALARM_SINGLE` a one-shot alarm (and no need to call [`tmr.unregister()`](#tmrunregister))
-`tmr.ALARM_SEMI` manually repeating alarm (call [`tmr.start()`](#tmrstart) to restart)
-`tmr.ALARM_AUTO` automatically repeating alarm
-`func(timer)` callback function which is invoked with the timer object as an argument
mytimer:interval(3000)-- actually, 3 seconds is better!
mytimer:start()
```
## tmr.obj:register()
Configures a timer and registers the callback function to call on expiry.
To free up the resources with this timer when done using it, call [`tmr.obj:unregister()`](#tmrobjunregister) on it. For one-shot timers this is not necessary, unless they were stopped before they expired.
#### Syntax
`mytmr:register(interval_ms, mode, func())`
#### Parameters
-`interval_ms` timer interval in milliseconds. Maximum value is 6870947 (1:54:30.947).
-`mode` timer mode:
-`tmr.ALARM_SINGLE` a one-shot alarm (and no need to call [`tmr.unregister()`](#tmrunregister))
-`tmr.ALARM_SEMI` manually repeating alarm (call [`tmr.start()`](#tmrunregister) to restart)
-`tmr.ALARM_AUTO` automatically repeating alarm
-`func(timer)` callback function which is invoked with the timer object as an argument