本文整理汇总了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)
示例2: loop
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import udelay [as 别名]
def loop(midiin):
while True:
midiin.poll()
pyb.udelay(50)
示例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)
示例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
示例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)
示例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
示例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