當前位置: 首頁>>代碼示例>>Python>>正文


Python pyb.udelay方法代碼示例

本文整理匯總了Python中pyb.udelay方法的典型用法代碼示例。如果您正苦於以下問題:Python pyb.udelay方法的具體用法?Python pyb.udelay怎麽用?Python pyb.udelay使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyb的用法示例。


在下文中一共展示了pyb.udelay方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import udelay [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: loop

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import udelay [as 別名]
def loop(midiin):
    while True:
        midiin.poll()
        pyb.udelay(50) 
開發者ID:SpotlightKid,項目名稱:micropython-stm-lib,代碼行數:6,代碼來源:printmidiin.py

示例3: _usleep

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import udelay [as 別名]
def _usleep(self, us):
        """Delay by (sleep) us microseconds."""
        # Wrapped as a method for portability
        pyb.udelay(us) 
開發者ID:SpotlightKid,項目名稱:micropython-stm-lib,代碼行數:6,代碼來源:hd44780.py

示例4: update

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import udelay [as 別名]
def update(t):                  # Interrupt handler may not be able to acquire the lock
    global var1, var2           # if main loop has it
    if mutex.test():            # critical section start
        var1 += 1
        pyb.udelay(200)
        var2 += 1
        mutex.release()         # critical section end 
開發者ID:peterhinch,項目名稱:micropython-samples,代碼行數:9,代碼來源:mutex_test.py

示例5: sleep_us

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import udelay [as 別名]
def sleep_us(self, useconds):
        try:
            time.sleep_us(useconds)
        except AttributeError:
            machine.udelay(useconds) 
開發者ID:Python-IoT,項目名稱:Smart-IoT-Planting-System,代碼行數:7,代碼來源:upcd8544.py

示例6: distance_in_cm

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import udelay [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

示例7: info

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import udelay [as 別名]
def info(self):
        self.pinCS.low()
        pyb.udelay(1000)                        # FLASH wake up delay
        self.spi.send(FLASH_RDID)
        manufacturer = self.spi.send_recv(FLASH_NOP)[0]
        id_high = self.spi.send_recv(FLASH_NOP)[0]
        id_low = self.spi.send_recv(FLASH_NOP)[0]
        self.pinCS.high()
        return manufacturer, id_high << 8 | id_low 
開發者ID:peterhinch,項目名稱:micropython-epaper,代碼行數:11,代碼來源:flash.py


注:本文中的pyb.udelay方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。