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


Python pyb.Timer方法代码示例

本文整理汇总了Python中pyb.Timer方法的典型用法代码示例。如果您正苦于以下问题:Python pyb.Timer方法的具体用法?Python pyb.Timer怎么用?Python pyb.Timer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyb的用法示例。


在下文中一共展示了pyb.Timer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def main():
    global var1, var2
    var1, var2 = 0, 0
    t2 = pyb.Timer(2, freq = 995, callback = update)
    t4 = pyb.Timer(4, freq = 1000, callback = update)
    for x in range(1000000):
        with mutex:             # critical section start
            a = var1
            pyb.udelay(200)
            b = var2
            result = a == b     # critical section end
        if not result:
            print('Fail after {} iterations'.format(x))
            break
        pyb.delay(1)
        if x % 1000 == 0:
            print(x)
    t2.deinit()
    t4.deinit()
    print(var1, var2) 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:22,代码来源:mutex_test.py

示例2: isr_test

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def isr_test():  # Test trigger from hard ISR
    from pyb import Timer
    s = '''
Timer holds off cb for 5 secs
cb should now run
cb callback
Done
'''
    printexp(s, 6)
    def cb(v):
        print('cb', v)

    d = Delay_ms(cb, ('callback',))

    def timer_cb(_):
        d.trigger(200)
    tim = Timer(1, freq=10, callback=timer_cb)

    print('Timer holds off cb for 5 secs')
    await asyncio.sleep(5)
    tim.deinit()
    print('cb should now run')
    await asyncio.sleep(1)
    print('Done') 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:26,代码来源:delay_test.py

示例3: callb

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def callb(timer):
	print("Timer tick")
	print(timer) 
开发者ID:martinribelotta,项目名称:uPyIDE,代码行数:5,代码来源:Main_Timers.py

示例4: init

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def init(timer_id = 2, nc_pin = 'Y3', gnd_pin = 'Y4', vcc_pin = 'Y1', data_pin = 'Y2'):
    global nc
    global gnd
    global vcc
    global data
    global micros
    global timer
    # Leave the pin unconnected
    if nc_pin is not None:
        nc = Pin(nc_pin)
        nc.init(Pin.OUT_OD)
        nc.high()
    # Make the pin work as GND
    if gnd_pin is not None:
        gnd = Pin(gnd_pin)
        gnd.init(Pin.OUT_PP)
        gnd.low()
    # Make the pin work as power supply
    if vcc_pin is not None:
        vcc = Pin(vcc_pin)
        vcc.init(Pin.OUT_PP)
        vcc.high()
    # Configure the pid for data communication
    data = Pin(data_pin)
    # Save the ID of the timer we are going to use
    timer = timer_id
    # setup the 1uS timer
    micros = pyb.Timer(timer, prescaler=83, period=0x3fffffff) # 1MHz ~ 1uS
    # Prepare interrupt handler
    ExtInt(data, ExtInt.IRQ_FALLING, Pin.PULL_UP, None)
    ExtInt(data, ExtInt.IRQ_FALLING, Pin.PULL_UP, edge)

# Start signal 
开发者ID:kurik,项目名称:uPython-DHT22,代码行数:35,代码来源:DHT22.py

示例5: __init__

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def __init__(self, length, adcpin, winfunc=None, timer=6):
        super().__init__(length, winfunc = winfunc)
        self.buff = array.array('i', (0 for x in range(self._length)))
        if isinstance(adcpin, pyb.ADC):
            self.adc = adcpin
        else:
            self.adc = pyb.ADC(adcpin)
        if isinstance(timer, pyb.Timer):
            self.timer = timer
        else:
            self.timer = pyb.Timer(timer)
        self.dboffset = PYBOARD_DBOFFSET # Value for Pyboard ADC 
开发者ID:peterhinch,项目名称:micropython-fourier,代码行数:14,代码来源:dftclass.py

示例6: __init__

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def __init__(self):
        self.read_count = 0
        self.dummy_count = 0
        self.ready_rd = False
        pyb.Timer(4, freq = 100, callback = self.do_input)

    # Read callback: emulate asynchronous input from hardware. 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:9,代码来源:test_fast_scheduling.py

示例7: __init__

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def __init__(self, read=False, write=False):
        self.ready_rd = False  # Read and write not ready
        self.wch = b''
        if read:
            self.rbuf = b'ready\n'  # Read buffer
            pyb.Timer(4, freq = 1, callback = self.do_input)
        if write:
            self.wbuf = bytearray(100)  # Write buffer
            self.wprint_len = 0
            self.widx = 0
            pyb.Timer(5, freq = 10, callback = self.do_output)

    # Read callback: emulate asynchronous input from hardware.
    # Typically would put bytes into a ring buffer and set .ready_rd. 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:16,代码来源:iotest4.py

示例8: __init__

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def __init__(self):
        self.ready_rd = False
        self.rbuf = b'ready\n'  # Read buffer
        pyb.Timer(4, freq = 1, callback = self.do_input)

    # Read callback: emulate asynchronous input from hardware.
    # Typically would put bytes into a ring buffer and set .ready_rd. 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:9,代码来源:iotest3.py

示例9: __init__

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def __init__(self, read=False, write=False):
        self.read_count = 0
        self.dummy_count = 0
        self.ready_rd = False
        pyb.Timer(4, freq = 100, callback = self.do_input)

    # Read callback: emulate asynchronous input from hardware. 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:9,代码来源:iotest6.py

示例10: __init__

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def __init__(self):
        self.ready_rd = False
        self.ready_wr = False
        self.wbuf = bytearray(100)  # Write buffer
        self.wprint_len = 0
        self.widx = 0
        self.wch = b''
        self.rbuf = b'ready\n'  # Read buffer
        pyb.Timer(4, freq = 1, callback = self.do_input)
        pyb.Timer(5, freq = 10, callback = self.do_output)

    # Read callback: emulate asynchronous input from hardware.
    # Typically would put bytes into a ring buffer and set .ready_rd. 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:15,代码来源:iotest1.py

示例11: __init__

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def __init__(self, read=False, write=False):
        self.ready_rd = False  # Read and write not ready
        self.rbuf = b'ready\n'  # Read buffer
        self.ridx = 0
        pyb.Timer(4, freq = 5, callback = self.do_input)
        self.wch = b''
        self.wbuf = bytearray(100)  # Write buffer
        self.wprint_len = 0
        self.widx = 0
        pyb.Timer(5, freq = 10, callback = self.do_output)

    # Read callback: emulate asynchronous input from hardware.
    # Typically would put bytes into a ring buffer and set .ready_rd. 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:15,代码来源:iotest5.py

示例12: __init__

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def __init__(self):
        self.ready = False
        self.count = 0
        tim = pyb.Timer(4)
        tim.init(freq=1)  # 1Hz - 1 simulated input line per sec.
        tim.callback(self.setready) 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:8,代码来源:iotest.py

示例13: backlight

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def backlight(self, percent):
# deferred init of LED PIN
        if self.pin_led is None:
# special treat for BG LED
            self.pin_led = pyb.Pin("Y3", pyb.Pin.OUT_PP)
            self.led_tim = pyb.Timer(4, freq=500)
            self.led_ch = self.led_tim.channel(3, pyb.Timer.PWM, pin=self.pin_led)
        percent = max(0, min(percent, 100))
        self.led_ch.pulse_width_percent(percent)  # set LED
#
# switch power on/off
# 
开发者ID:peterhinch,项目名称:micropython-tft-gui,代码行数:14,代码来源:tft.py

示例14: test

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def test(fast_io=True, latency=False):
    loop = asyncio.get_event_loop(ioq_len=6 if fast_io else 0)
    pinin = pyb.Pin(pyb.Pin.board.X2, pyb.Pin.IN)
    pyb.Timer(4, freq = 2.1, callback = toggle)
    for _ in range(5):
        loop.create_task(dummy())
    if latency:
        pin_cb = PinCall(pinin, cb_rise = cbl, cbr_args = (pinin,))
    else:
        pincall = PinCall(pinin, cb_rise = cb, cbr_args = (pinin, 'rise'), cb_fall = cb, cbf_args = (pinin, 'fall'))
    loop.run_until_complete(killer()) 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:13,代码来源:pin_cb_test.py

示例15: distance_in_cm

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Timer [as 别名]
def distance_in_cm(self):
        start = 0
        end = 0

        # Create a microseconds counter.
        micros = pyb.Timer(2, prescaler=83, period=0x3fffffff)
        micros.counter(0)

        # Send a 10us pulse.
        self.trigger.high()
        pyb.udelay(10)
        self.trigger.low()

        # Wait 'till whe pulse starts.
        while self.echo.value() == 0:
            start = micros.counter()

        # Wait 'till the pulse is gone.
        while self.echo.value() == 1:
            end = micros.counter()

        # Deinit the microseconds counter
        micros.deinit()

        # Calc the duration of the recieved pulse, divide the result by
        # 2 (round-trip) and divide it by 29 (the speed of sound is
        # 340 m/s and that is 29 us/cm).
        dist_in_cm = ((end - start) / 2) / 29

        return dist_in_cm 
开发者ID:mithru,项目名称:MicroPython-Examples,代码行数:32,代码来源:ultrasonic.py


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