Jump to content
Electronics-Lab.com Community

Program Periodical Timer on Microcontroller with Python -- Ameba MicroPython


MENG XI

Recommended Posts

Time is very useful when come to medium size project that requires periodical triggering of certain task over time, here we are going to show you how ot program Ameba RTL8722 dual-band wifi and BLE microcontrollers,

 

Materials

  • Ameba x 1

Steps

There are 3 sets of general timers available to user, each at 32KHz, they are timer 1/2/3.
Here we use timer 1 as example to demonstrate how a periodical timer works.

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.start(2000000, t.PERIODICAL) # Set GTimer fired periodically at duration of 2 seconds, printing text on the terminal
 
# To stop the periodical timer, type
t.stop()

A text of “–timer triggered. to stop: type t.stop()–” will be printed on the terminal every 2 seconds.To stop the timer, simply type t.stop().

Link to comment
Share on other sites


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
  • Create New...