当前位置: 首页>>代码示例>>Python>>正文


Python Timer.PERIODIC属性代码示例

本文整理汇总了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 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:25,代码来源:soft_wdt.py

示例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 
开发者ID:1zlab,项目名称:1ZLAB_PyEspCar,代码行数:22,代码来源:battery_voltage.py

示例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 
开发者ID:micropython-Chinese-Community,项目名称:mpy-lib,代码行数:14,代码来源:irqUART.py

示例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的引脚 
开发者ID:1zlab,项目名称:1ZLAB_MicroPython_ESP32_Tutorial,代码行数:15,代码来源:timer_led_blink.py

示例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的引脚 
开发者ID:1zlab,项目名称:1ZLAB_MicroPython_ESP32_Tutorial,代码行数:15,代码来源:timer_rgb_blink.py

示例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 
开发者ID:idimitrakopoulos,项目名称:illuminOS,代码行数:13,代码来源:NodeMCU.py

示例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 
开发者ID:idimitrakopoulos,项目名称:illuminOS,代码行数:13,代码来源:NodeMCU.py

示例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()) 
开发者ID:idimitrakopoulos,项目名称:illuminOS,代码行数:7,代码来源:Board.py


注:本文中的machine.Timer.PERIODIC属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。