Timer - Control Hardware Timers
This class provides the method of controlling hardware timer.
Note: For Timer0 to Timer3, each of them can only execute one task at the same time and multiple objects cannot use the same timer.
Constructor #
machine.Timer
#
Parameter:
-
Timern
- Integer type. Timer number. Timer0 to Timer3 are supported.
Example:
Methods #
timer.start
#
This method enables the timer.
Parameter:
-
period
- Integer type. Interruption period. Unit: millisecond. The period is greater than or equal to 1. -
mode
- Integer type. Running mode.
ONE_SHOT
- Single mode indicating the time is executed for only once.
PERIODIC
- Periodic mode indicates periodic execution. -
callback
- Function type. Timer execution function.
Return Value:
0
- Successful execution
-1
- Failed execution
Example:
timer.stop
#
This method disables the timer.
Return Value:
0
- Successful execution
-1
- Failed execution
Example:
Constants #
Constant | Description |
---|---|
Timer.Timer0 | Timer 0 |
Timer.Timer1 | Timer 1 |
Timer.Timer2 | Timer 2 |
Timer.Timer3 | Timer 3 |
Timer.ONE_SHOT | Single mode indicating the time is executed for only once. |
Timer.PERIODIC | Periodic mode indicates periodic execution. |