當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。