本文整理匯總了Python中pyb.Timer.init方法的典型用法代碼示例。如果您正苦於以下問題:Python Timer.init方法的具體用法?Python Timer.init怎麽用?Python Timer.init使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyb.Timer
的用法示例。
在下文中一共展示了Timer.init方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Timer
# 需要導入模塊: from pyb import Timer [as 別名]
# 或者: from pyb.Timer import init [as 別名]
import pyb
from pyb import Timer
tim = Timer(4)
tim = Timer(4, prescaler=100, period=200)
print(tim.prescaler())
print(tim.period())
tim.prescaler(300)
print(tim.prescaler())
tim.period(400)
print(tim.period())
tim = Timer(4, freq=1)
tim.init(freq=2000)
def f(t):
print(1)
t.callback(None)
tim.callback(f)
pyb.delay(10)
# f3 closes over f2.y
def f2(x):
y = x
def f3(t):
print(2, y)
t.callback(None)
return f3
tim.callback(f2(3))
pyb.delay(10)
示例2: print
# 需要導入模塊: from pyb import Timer [as 別名]
# 或者: from pyb.Timer import init [as 別名]
print("cb4", y)
t.callback(None)
return cb4
# create a timer with a callback, using callback(None) to stop
tim = Timer(1, freq=100, callback=cb1)
pyb.delay(5)
print("before cb1")
pyb.delay(15)
# create a timer with a callback, using deinit to stop
tim = Timer(2, freq=100, callback=cb2)
pyb.delay(5)
print("before cb2")
pyb.delay(15)
# create a timer, then set the freq, then set the callback
tim = Timer(4)
tim.init(freq=100)
tim.callback(cb1)
pyb.delay(5)
print("before cb1")
pyb.delay(15)
# test callback with a closure
tim.init(freq=100)
tim.callback(cb3(3))
pyb.delay(5)
print("before cb4")
pyb.delay(15)