當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。