本文整理汇总了Python中time.sleep_ms方法的典型用法代码示例。如果您正苦于以下问题:Python time.sleep_ms方法的具体用法?Python time.sleep_ms怎么用?Python time.sleep_ms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类time
的用法示例。
在下文中一共展示了time.sleep_ms方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tone
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def tone(self, freq=1800, duration=200, volume=None, timer=True):
duration = min(max(30, duration), 2000)
freq = min(max(20, freq), 20000)
self.checkInit()
if volume == None:
self.pwm.init(freq=freq, duty=self._volume)
else:
self.pwm.init(freq=freq, duty=volume)
if timer:
# if self._timer.isrunning():
# self._timer.period(duration)
# else:
self._timer.init(period=duration, mode=self._timer.ONE_SHOT, callback=self._timeout_cb)
time.sleep_ms(duration-15)
else:
time.sleep_ms(duration)
self.pwm.duty(0)
time.sleep_ms(1)
self.pwm.freq(1)
示例2: playnotes
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def playnotes(self, title, length=150, duty=64):
if title not in self.notes:
print('unknown title: {}'.format(title))
return
melody = self.notes[title]
print('Play', title)
for i in melody:
if i == 0:
self.pwm.duty(0)
else:
self.pwm.freq(i)
self.pwm.duty(duty)
time.sleep_ms(length)
self.pwm.duty(0)
示例3: main
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def main():
c.set_callback(sub_cb)
if not wait_network():
print('Cannot connect WiFi')
raise Exception('Cannot connect WiFi')
c.connect()
if conf.data['orgID'] != 'quickstart':
c.subscribe(ledCommandTopic)
c.subscribe(irCommandTopic)
print('Connected, waiting for event ({})'.format(conf.data['deviceID']))
status = {'d': {'sine':{}}}
count = 0
try:
while True:
status['d']['sine'] = sineVal(-1.0, 1.0, 16, count)
count += 1
c.publish(statusTopic, json.dumps(status))
time.sleep_ms(10000)
#c.wait_msg()
c.check_msg()
finally:
c.disconnect()
print('Disonnected')
示例4: playnotes
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def playnotes(self, title, length=150, duty=64):
# Init
p = Pin(27, Pin.OUT)
self.pwm = PWM(p)
self.pwm.duty(0)
if title not in self.notes:
print('unknown title: {}'.format(title))
return
melody = self.notes[title]
print('Play', title)
for i in melody:
if i == 0:
self.pwm.duty(0)
else:
self.pwm.freq(i)
self.pwm.duty(duty)
time.sleep_ms(length)
# deinit
self.pwm.deinit()
示例5: measure
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def measure(self):
buf = self.buf
address = self.address
# wake sensor
try:
self.i2c.writeto(address, b'')
except OSError:
pass
# read 4 registers starting at offset 0x00
self.i2c.writeto(address, b'\x03\x00\x04')
# wait at least 1.5ms
time.sleep_ms(2)
# read data
self.i2c.readfrom_mem_into(address, 0, buf)
# debug print
print(ustruct.unpack('BBBBBBBB', buf))
crc = ustruct.unpack('<H', bytearray(buf[-2:]))[0]
if (crc != self.crc16(buf[:-2])):
raise Exception("checksum error")
示例6: __init__
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def __init__(self, width, height, spi, dc, res, cs, external_vcc=False):
self.rate = 10 * 1024 * 1024
dc.init(dc.OUT, value=0)
res.init(res.OUT, value=0)
cs.init(cs.OUT, value=1)
self.spi = spi
self.dc = dc
self.res = res
self.cs = cs
import time
self.res(1)
time.sleep_ms(1)
self.res(0)
time.sleep_ms(10)
self.res(1)
super().__init__(width, height, external_vcc)
示例7: send_cmd
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def send_cmd(self, cmd_request, response_size=6, read_delay_ms=100):
"""
Send a command to the sensor and read (optionally) the response
The responsed data is validated by CRC
"""
try:
self.i2c.start();
self.i2c.writeto(self.i2c_addr, cmd_request);
if not response_size:
self.i2c.stop();
return
time.sleep_ms(read_delay_ms)
data = self.i2c.readfrom(self.i2c_addr, response_size)
self.i2c.stop();
for i in range(response_size//3):
if not self._check_crc(data[i*3:(i+1)*3]): # pos 2 and 5 are CRC
raise SHT30Error(SHT30Error.CRC_ERROR)
if data == bytearray(response_size):
raise SHT30Error(SHT30Error.DATA_ERROR)
return data
except OSError as ex:
if 'I2C' in ex.args[0]:
raise SHT30Error(SHT30Error.BUS_ERROR)
raise ex
示例8: loop
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def loop():
show_temp = True
while True:
g = get()
display.fill(0)
display.text("Weather in", 0, 0)
display.text(g['name'], 0, 8)
if left_button.value() == 0 or right_button.value() == 0:
show_temp = not show_temp
if show_temp:
celsius = g['main']['temp'] - 273.15
display.text("Temp/C: %.1f" % celsius, 0, 24)
display.text("Temp/F: %.1f" % (celsius * 1.8 + 32), 0, 32)
else: # humidity
display.text("Humidity: %d%%" % g['main']['humidity'], 0, 24)
if lower_button.value() == 0:
break
display.show()
time.sleep_ms(500)
示例9: get_sensor_avg
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def get_sensor_avg(self, samples, softstart=100):
'''Return the average readings from the sensors over the
given number of samples. Discard the first softstart
samples to give things time to settle.'''
sample = self.read_sensors()
counters = [0] * 7
for i in range(samples + softstart):
# the sleep here is to ensure we read a new sample
# each time
time.sleep_ms(2)
sample = self.read_sensors()
if i < softstart:
continue
for j, val in enumerate(sample):
counters[j] += val
return [x//samples for x in counters]
示例10: wifi_reset
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def wifi_reset():
global uart
wifi_enable(0)
time.sleep_ms(200)
wifi_enable(1)
time.sleep(2)
uart = UART(UART.UART2,115200,timeout=1000, read_buf_len=4096)
tmp = uart.read()
uart.write("AT+UART_CUR=921600,8,1,0,0\r\n")
print(uart.read())
uart = UART(UART.UART2,921600,timeout=1000, read_buf_len=10240) # important! baudrate too low or read_buf_len too small will loose data
uart.write("AT\r\n")
tmp = uart.read()
print(tmp)
if not tmp.endswith("OK\r\n"):
print("reset fail")
return None
try:
nic = network.ESP8285(uart)
except Exception:
return None
return nic
示例11: cmd_join_ap_and_wait
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def cmd_join_ap_and_wait(self):
print("[cmd join ap]")
recv = self.uart.read()
print(recv)
if self.passwd:
self.uart.write(b'AT+CWJAP_DEF="{}","{}"\r\n'.format(self.ssid, self.passwd))
else:
self.uart.write(b'AT+CWJAP_DEF="{}"\r\n'.format(self.ssid))
time.sleep_ms(200)
print("[wait join ap -- 0]")
read = b""
tim = time.ticks_ms()
while 1:
if time.ticks_ms() - tim > 10000:
return False
recv = self.uart.read()
if recv:
print(recv)
else:
print(".", end='')
if recv:
read += recv
if b"GOT IP" in read:
return True
示例12: wait_join_ap
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def wait_join_ap(self):
print("[wait join ap]")
read = b""
tim = time.ticks_ms()
while 1:
if time.ticks_ms() - tim > 10000:
raise Exception("wait for join AP timeout")
recv = self.uart.read()
if recv:
print(recv)
else:
print(".", end='')
if recv:
read += recv
if b"GOT IP" in read:
break
time.sleep_ms(1000)
read = self.uart.read()
print(read)
示例13: wait_upgrade
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def wait_upgrade(self):
print("[wait upgrade process]")
read = b""
tim = time.ticks_ms()
while 1:
if time.ticks_ms() - tim > 80000:
raise Exception("wait for update timeout")
recv = self.uart.read()
if recv:
print(recv)
else:
print(".", end='')
if recv:
read += recv
if self.update_step != 4 and b"+CIPUPDATE:4" in read:
self.update_step = 4
if self.update_step == 4 and b"OK" in read:
break
time.sleep_ms(200)
示例14: wifi_reset
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def wifi_reset():
global uart
wifi_enable(0)
time.sleep_ms(200)
wifi_enable(1)
time.sleep(2)
uart = UART(UART.UART2,115200,timeout=1000, read_buf_len=4096)
tmp = uart.read()
uart.write("AT+UART_CUR=921600,8,1,0,0\r\n")
print(uart.read())
uart = UART(UART.UART2,921600,timeout=1000, read_buf_len=10240) # important! baudrate too low or read_buf_len too small will loose data
uart.write("AT\r\n")
tmp = uart.read()
print(tmp)
if not tmp.endswith("OK\r\n"):
print("reset fail")
return None
try:
nic = network.ESP8285(uart)
except Exception:
return None
return nic
示例15: wifi_reset
# 需要导入模块: import time [as 别名]
# 或者: from time import sleep_ms [as 别名]
def wifi_reset():
global uart
wifi_enable(0)
time.sleep_ms(200)
wifi_enable(1)
time.sleep(2)
uart = UART(UART.UART2,115200,timeout=1000, read_buf_len=4096)
tmp = uart.read()
uart.write("AT+UART_CUR=921600,8,1,0,0\r\n")
print(uart.read())
uart = UART(UART.UART2,921600,timeout=1000, read_buf_len=4096)
uart.write("AT\r\n")
tmp = uart.read()
print(tmp)
if not tmp.endswith("OK\r\n"):
print("reset fail")
return None
try:
nic = network.ESP8285(uart)
except Exception:
return None
return nic