# check callback feature of the timer classimport pybfrom pyb import Timer# callback function that disables the callback when calleddef cb1(t):print("cb1")t.callback(None)# callback function that disables the timer when calleddef cb2(t):print("cb2")t.deinit()# callback where cb4 closes over cb3.ydef cb3(x):y = xdef cb4(t):print("cb4", y)t.callback(None)return cb4# create a timer with a callback, using callback(None) to stoptim = Timer(1, freq=100, callback=cb1)pyb.delay(5)print("before cb1")pyb.delay(15)# create a timer with a callback, using deinit to stoptim = 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 callbacktim = Timer(4)tim.init(freq=100)tim.callback(cb1)pyb.delay(5)print("before cb1")pyb.delay(15)# test callback with a closuretim.init(freq=100)tim.callback(cb3(3))pyb.delay(5)print("before cb4")pyb.delay(15)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。