Gtimer - Use the periodic GTimer

Materials

  • AmebaD [ AMB23 / AMB21 / AMB22 / BW16 / BW16-TypeC ] x 1

Example

There are 3 sets of general timers available to user, each at 32KHz, they are timer 1/2/3.

Unit Timer Freq
1
TIMER1
32KHz
2
TIMER2
32KHz
3
TIMER3
32KHz

Here we use timer 1 as example to demonstrate how a periodical timer works.

Code

Copy and paste the first 3 lines of code into REPL to see its effect.

from machine import Timer
t = Timer(1)  # Use Timer 1/2/3 only
t.init(t.PERIODIC, 2000)  # Set GTimer fired periodically at duration of 2 seconds, printing text on the terminal

# To stop the periodical timer, type
t.deinit()
Please confirm that QQ communication software is installed