本文整理匯總了Python中time.sleep_us方法的典型用法代碼示例。如果您正苦於以下問題:Python time.sleep_us方法的具體用法?Python time.sleep_us怎麽用?Python time.sleep_us使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類time
的用法示例。
在下文中一共展示了time.sleep_us方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _send_pulse_and_wait
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def _send_pulse_and_wait(self):
"""
Send the pulse to trigger and listen on echo pin.
We use the method `machine.time_pulse_us()` to get the microseconds until the echo is received.
"""
self.trigger.value(0) # Stabilize the sensor
time.sleep_us(5)
self.trigger.value(1)
# Send a 10us pulse.
time.sleep_us(10)
self.trigger.value(0)
try:
pulse_time = machine.time_pulse_us(self.echo, 1, self.echo_timeout_us)
return pulse_time
except OSError as ex:
if ex.args[0] == 110: # 110 = ETIMEDOUT
raise OSError('Out of range')
raise ex
示例2: readVoRaw
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def readVoRaw(self, samplingTime, deltaTime):
# Turn on ILED
self.sharpLEDPin.value(0)
# Wait 0.28ms
time.sleep_us(samplingTime)
VoRaw = self.sharpVoPin.read()
# Wait 0.04ms
time.sleep_us(deltaTime)
# Turn off ILED
self.sharpLEDPin.value(1)
return VoRaw
示例3: _pulse
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def _pulse(self) -> int:
"""
Send a pulse and wait for the echo pin using machine.time_pulse_us() to measure us.
:return: int
"""
tr = self._tr
tr.value(0)
time.sleep_us(5)
tr.value(1)
time.sleep_us(10)
tr.value(0)
try:
return machine.time_pulse_us(self._ec, 1, self._to)
except OSError as e:
if e.args[0] == 100: # TIMEOUT
raise OSError("Object too far")
raise e
示例4: readValue
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def readValue():
global Voc, Vos, idx
VoRaw = dust_sensor.readRawVo(220, 40) # adjusted 280 -> 220
# Compute the output voltage in Volts.
Vo = VoRaw / 4095.0 * 5.0
# Exponential Moving Average
# https://www.investopedia.com/terms/e/ema.asp
# EMA(t) = Value(t)*k + EMA(y) * (1-k)
# k = 2 / (N+1)
# k = 0.005 where N = 399
Vos = Vo * 0.005 + Vos * 0.995
# print('{}, {}, {}, {}'.format(idx, VoRaw, Vo*1000.0, Vos*1000.0))
density = (Vos - 0.6) / 0.5 * 100.0
if density < 0:
density = 0
print('{}, {}, {}'.format(Vo*1000.0, Vos*1000.0, density*10))
status_box.text(density+'ug/m3')
idx += 1
#time.sleep_us(10000 - 320)
time.sleep_us(4000)
示例5: readValue
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def readValue():
global Voc, Vos, idx
# Turn on ILED
sharpLEDPin.value(0)
# Wait 0.28 ms
time.sleep_us(280)
VoRaw = sharpVoPin.read()
# Wait 0.04 ms
#time.sleep_us(40)
# Turn off ILED
sharpLEDPin.value(1)
# Compute the output voltage in Volts.
Vo = VoRaw / 4095.0 * 3.3
# Exponential Moving Average
# https://www.investopedia.com/terms/e/ema.asp
# EMA(t) = Value(t)*k + EMA(y) * (1-k)
# k = 2 / (N+1)
# k = 0.005 where N = 399
Vos = Vo * 0.005 + Vos * 0.995
dV = Vos - Voc
if dV < 0:
dV = 0
Voc = Vo
# Convert to Dust Density in units of ug/m3.
dustDensity = dV / K * 100.0
print('VoRaw={}, Vo={} mV, Density={} ug/m3'.format(VoRaw, Vo*1000.0, dustDensity))
idx += 1
time.sleep_us(10000 - 320)
示例6: readValue
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def readValue():
global Voc
# Turn on ILED
sharpLEDPin.value(0)
# Wait 0.28 ms
# time.sleep_us(280) # Actually, it took 0.4 ms.
time.sleep_us(196) # It was measured about value of 0.28 ms
VoRaw = sharpVoPin.read()
# Wait 0.04 ms
#time.sleep_us(40)
# Turn off ILED
sharpLEDPin.value(1)
# Compute the output voltage in Volts.
Vo = VoRaw / 4095.0 * 5.0
# Convert to Dust Density in units of ug/m3.
dV = Vo - Voc
if dV < 0:
dV = 0
Voc = Vo
dustDensity = dV / K * 100.0
print('VoRaw={}, Vo={} mV, Density={} ug/m3'.format(VoRaw, Vo*1000.0, dustDensity))
#time.sleep_us(10000 - 320)
time.sleep_us(4000)
示例7: readValue
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def readValue():
global Voc
# Turn on ILED
sharpLEDPin.value(0)
# Wait 0.28 ms
time.sleep_us(280)
VoRaw = sharpVoPin.read()
# Wait 0.04 ms
#time.sleep_us(40)
# Turn off ILED
sharpLEDPin.value(1)
# Compute the output voltage in Volts.
Vo = VoRaw / 4095.0 * 3.3
# Convert to Dust Density in units of ug/m3.
dV = Vo - Voc
if dV < 0:
dV = 0
Voc = Vo
# Convert to Dust Density in units of ug/m3.
dustDensity = dV / K * 100.0
print('VoRaw={}, Vo={} mV, Density={} ug/m3'.format(VoRaw, Vo*1000.0, dustDensity))
time.sleep_us(10000 - 320)
示例8: freq
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def freq(self, freq=None):
if freq is None:
return int(25000000.0 / 4096 / (self._read(0xfe) - 0.5))
prescale = int(25000000.0 / 4096.0 / freq + 0.5)
old_mode = self._read(0x00) # Mode 1
self._write(0x00, (old_mode & 0x7F) | 0x10) # Mode 1, sleep
self._write(0xfe, prescale) # Prescale
self._write(0x00, old_mode) # Mode 1
time.sleep_us(5)
self._write(0x00, old_mode | 0xa1) # Mode 1, autoincrement on
示例9: sleep_us
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def sleep_us(self, useconds):
try:
time.sleep_us(useconds)
except AttributeError:
machine.udelay(useconds)
示例10: reset
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def reset(self):
""" issue reset impulse to reset the display """
self.rst.value(0) # RST on
self.sleep_us(100) # reset impulse has to be >100 ns and <100 ms
self.rst.value(1) # RST off
# Defaults after reset:
self.power = self.POWER_DOWN
self.addressing = self.ADDRESSING_HORIZ
self.instr = self.INSTR_BASIC
self.display_mode = self.DISPLAY_BLANK
self.temp_coeff = self.TEMP_COEFF_0
self.bias = self.BIAS_1_11
self.voltage = 3060
示例11: _send_pulse_and_wait
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def _send_pulse_and_wait(self):
"""
Send the pulse to trigger and listen on echo pin.
We use the method `machine.time_pulse_us()` to get the microseconds until the echo is received.
"""
self.trigger.value(0) # Stabilize the sensor
time.sleep_us(5)
self.trigger.value(1)
# Send a 10us pulse.
time.sleep_us(10)
self.trigger.value(0)
try:
if (uname().sysname == 'WiPy'):
pulse_list = pulses_get(self.echo, self.echo_timeout_us)
if(len(pulse_list) == 0):
pulse_time = -1
else:
pulse_time = pulse_list[0][1]
else:
pulse_time = time_pulse_us(self.echo, 1, self.echo_timeout_us)
return pulse_time
except OSError as ex:
if ex.args[0] == 110: # 110 = ETIMEDOUT
raise OSError('Out of range')
raise ex
示例12: _reset
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def _reset( self ) :
'''Reset the device.'''
self.dc(0)
self.reset(1)
time.sleep_us(500)
self.reset(0)
time.sleep_us(500)
self.reset(1)
time.sleep_us(500)
示例13: write_clk
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def write_clk(self):
self.clk.value(0)
time.sleep_us(20)
self.clk.value(1)
time.sleep_us(20)
示例14: readValue
# 需要導入模塊: import time [as 別名]
# 或者: from time import sleep_us [as 別名]
def readValue():
global Voc, Vos, idx
# Turn on ILED
sharpLEDPin.value(0)
# Wait 0.28 ms
# time.sleep_us(280) # Actually, it took 0.4 ms.
time.sleep_us(196) # It was measured about value of 0.28 ms
VoRaw = sharpVoPin.read()
# Wait 0.04 ms
#time.sleep_us(40)
# Turn off ILED
sharpLEDPin.value(1)
# Compute the output voltage in Volts.
Vo = VoRaw / 4095.0 * 3.3
# Exponential Moving Average
# https://www.investopedia.com/terms/e/ema.asp
# EMA(t) = Value(t)*k + EMA(y) * (1-k)
# k = 2 / (N+1)
# k = 0.005 where N = 399
Vos = Vo * 0.005 + Vos * 0.995
dV = Vos - Voc
if dV < 0:
dV = 0
# Convert to Dust Density in units of ug/m3.
dustDensity = dV / K * 100.0
#print('VoRaw={}, Vo={} mV, Density={} ug/m3'.format(VoRaw, Vo*1000.0, dustDensity))
print('{}, {}, {}'.format(idx, Vo*1000.0, Vos*1000.0))
status_box.text(str(dustDensity)+'ug/m3')
idx += 1
#time.sleep_us(10000 - 320)
time.sleep_us(4000)