本文整理匯總了Python中machine.Timer.PERIODIC屬性的典型用法代碼示例。如果您正苦於以下問題:Python Timer.PERIODIC屬性的具體用法?Python Timer.PERIODIC怎麽用?Python Timer.PERIODIC使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類machine.Timer
的用法示例。
在下文中一共展示了Timer.PERIODIC屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: wdt
# 需要導入模塊: from machine import Timer [as 別名]
# 或者: from machine.Timer import PERIODIC [as 別名]
def wdt(secs=0):
timer = Timer(-1)
timer.init(period=1000, mode=Timer.PERIODIC, callback=lambda t:wdt_feed())
cnt = secs
run = False # Disable until 1st feed
def inner(feed=WDT_CB):
nonlocal cnt, run, timer
if feed > 0: # Call with variable timeout
cnt = feed
run = True
elif feed == 0: # Fixed timeout
cnt = secs
run = True
elif feed < 0: # WDT control/callback
if feed == WDT_SUSPEND:
run = False # Temporary suspension
elif feed == WDT_CANCEL:
timer.deinit() # Permanent cancellation
elif feed == WDT_CB and run: # Timer callback and is running.
cnt -= 1
if cnt <= 0:
reset()
return inner
示例2: __init__
# 需要導入模塊: from machine import Timer [as 別名]
# 或者: from machine.Timer import PERIODIC [as 別名]
def __init__(self, gpio_id, is_debug=False):
self.BV_SAMPLE_PERIOD = 100 # 采樣周期(次數)為2000次
self.OVER_DISCHARGE_VOLTAGE = 6.4 # 過放電壓參考值
self.pin = Pin(gpio_id, Pin.IN) # 電壓采樣引腳
self.adc = ADC(self.pin) # 創建引腳對應的ADC對象
self.init_adc() # 初始化ADC
self.bv_sample_cnt = 0 # 統計次數
self.bv_sample_sum = 0 # 采樣電壓總和
self.battery_voltage = 0 # 電池電壓
# 初始化電池電壓
self.init_battery_voltage()
# 創建一個定時器
# self.timer = Timer(timer_id)
# 每隔1ms執行一次
# self.timer.init(period=1, mode=Timer.PERIODIC, callback=self.callback)
# 電池是否過放
self.is_over_discharge = False # 電池是否過放
# 是否開啟調試模式
self.is_debug = is_debug
示例3: __init__
# 需要導入模塊: from machine import Timer [as 別名]
# 或者: from machine.Timer import PERIODIC [as 別名]
def __init__(self, uart, rx_pin, rx_irq=None, frame_irq=None, CHR_TMO=3, FRAME_TMO=100):
self._rxpin = rx_pin
self._rxirq = rx_irq
self._frameirq = frame_irq
self._CHR_TMO = CHR_TMO
self._FRAME_TMO = FRAME_TMO
self._rxpin.init(Pin.IN)
self._rxpin.irq(trigger = Pin.IRQ_FALLING, handler = self._RXPIN_IRQ)
self._TMRX = Timer(-1)
self._TMRX_sta = 0
self._mode = Timer.ONE_SHOT if sys.platform == 'pyboard' else Timer.PERIODIC
self.uart = uart
示例4: led_blink_timed
# 需要導入模塊: from machine import Timer [as 別名]
# 或者: from machine.Timer import PERIODIC [as 別名]
def led_blink_timed(timer, led_pin, freq=10):
'''
led 按照特定的頻率進行閃爍
LED閃爍周期 = 1000ms / 頻率
狀態變換間隔(period) = LED閃爍周期/ 2
'''
# 計算狀態變換間隔時間 ms
period = int(0.5 * 1000 / freq)
# 初始化定時器
timer.init(period=period, mode=Timer.PERIODIC, callback=lambda t:led_toggle(led_pin))
# 聲明引腳 D12 作為LED的引腳
示例5: led_blink_timed
# 需要導入模塊: from machine import Timer [as 別名]
# 或者: from machine.Timer import PERIODIC [as 別名]
def led_blink_timed(timer, led_pin, freq=10):
'''
led 按照特定的頻率進行閃爍
LED閃爍周期 = 1000ms / 頻率
狀態變換間隔(period) = LED閃爍周期/ 2
'''
# 計算狀態變換間隔時間 ms
period = int(0.5 * 1000 / freq)
# 初始化定時器
timer.init(period=period, mode=Timer.PERIODIC, callback=lambda t:led_toggle(led_pin))
# 聲明引腳 D32 作為LED的引腳
示例6: get_flash_button_events
# 需要導入模塊: from machine import Timer [as 別名]
# 或者: from machine.Timer import PERIODIC [as 別名]
def get_flash_button_events(self, on_single_click, on_double_click):
from machine import Timer
Board.button_click_counter['flash'] = 0
pin = self.get_pin_by_key("BTN_FLASH")
tim = Timer(0)
tim.init(period=200, mode=Timer.PERIODIC, callback=lambda t: Board.get_onboard_button_events(self, pin, 'flash', on_single_click, on_double_click))
# @timed_function
示例7: get_user_button_events
# 需要導入模塊: from machine import Timer [as 別名]
# 或者: from machine.Timer import PERIODIC [as 別名]
def get_user_button_events(self, on_single_click, on_double_click):
from machine import Timer
Board.button_click_counter['user'] = 0
pin = self.get_pin_by_key("BTN_USER")
tim = Timer(0)
tim.init(period=200, mode=Timer.PERIODIC, callback=lambda t: Board.get_onboard_button_events(self, pin, 'user', on_single_click, on_double_click))
# @timed_function
示例8: start_memory_manager
# 需要導入模塊: from machine import Timer [as 別名]
# 或者: from machine.Timer import PERIODIC [as 別名]
def start_memory_manager(self, period=5000):
from machine import Timer
tim = Timer(0)
tim.init(period=period, mode=Timer.PERIODIC, callback=lambda t: self.mem_cleanup())