当前位置: 首页>>代码示例>>Python>>正文


Python time.sleep_ms方法代码示例

本文整理汇总了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) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:21,代码来源:speak.py

示例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) 
开发者ID:IBM-Developer-Korea,项目名称:developer-badge-2018-apps,代码行数:18,代码来源:buzzer.py

示例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') 
开发者ID:IBM-Developer-Korea,项目名称:developer-badge-2018-apps,代码行数:27,代码来源:iot_client.py

示例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() 
开发者ID:IBM-Developer-Korea,项目名称:developer-badge-2018-apps,代码行数:24,代码来源:buzzer.py

示例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") 
开发者ID:mcauser,项目名称:MicroPython-ESP8266-DHT-Nokia-5110,代码行数:21,代码来源:am2320.py

示例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) 
开发者ID:tinypico,项目名称:tinypico-micropython,代码行数:18,代码来源:ssd1306.py

示例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 
开发者ID:rsc1975,项目名称:micropython-sht30,代码行数:26,代码来源:sht30.py

示例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) 
开发者ID:ulno,项目名称:ulnoiot-upy,代码行数:21,代码来源:weather.py

示例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] 
开发者ID:larsks,项目名称:py-mpu6050,代码行数:22,代码来源:mpu6050.py

示例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 
开发者ID:sipeed,项目名称:MaixPy_scripts,代码行数:24,代码来源:demo_http.py

示例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 
开发者ID:sipeed,项目名称:MaixPy_scripts,代码行数:26,代码来源:upgrade_at_firmware.py

示例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) 
开发者ID:sipeed,项目名称:MaixPy_scripts,代码行数:21,代码来源:upgrade_at_firmware.py

示例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) 
开发者ID:sipeed,项目名称:MaixPy_scripts,代码行数:21,代码来源:upgrade_at_firmware.py

示例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 
开发者ID:sipeed,项目名称:MaixPy_scripts,代码行数:24,代码来源:demo_net_socket.py

示例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 
开发者ID:sipeed,项目名称:MaixPy_scripts,代码行数:24,代码来源:demo_send_pic.py


注:本文中的time.sleep_ms方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。