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


Python utime.sleep方法代码示例

本文整理汇总了Python中utime.sleep方法的典型用法代码示例。如果您正苦于以下问题:Python utime.sleep方法的具体用法?Python utime.sleep怎么用?Python utime.sleep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utime的用法示例。


在下文中一共展示了utime.sleep方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: scroll

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def scroll(use_spi=False, soft=True):
    ssd = setup(use_spi, soft)  # Create a display instance
    rhs = WIDTH -1
    ssd.line(rhs - 20, 0, rhs, 20, 1)
    square_side = 10
    ssd.fill_rect(rhs - square_side, 0, square_side, square_side, 1)

    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, freesans20, verbose=False)
    wri.set_clip(False, False, False)  # Char wrap
    wri.printstring('Sunday\n')
    wri.printstring('12 Aug 2018\n')
    wri.printstring('10.30am')
    for x in range(5):
        ssd.show()
        utime.sleep(2)
        wri.printstring('\nCount = {:2d}'.format(x))
    ssd.show()
    utime.sleep(2)
    wri.printstring('\nDone.')
    ssd.show() 
开发者ID:peterhinch,项目名称:micropython-font-to-py,代码行数:23,代码来源:writer_tests.py

示例2: usd_scroll

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def usd_scroll(use_spi=False, soft=True):
    ssd = setup(use_spi, soft)  # Create a display instance
    # Only CWriter can do usd
    CWriter.invert_display(ssd)
    CWriter.set_textpos(ssd, 0, 0)
    wri = CWriter(ssd, freesans20, verbose=False)
    wri.set_clip(False, False, False)  # Char wrap

    wri.printstring('Sunday\n')
    wri.printstring('12 Aug 2018\n')
    wri.printstring('10.30am')
    for x in range(5):
        ssd.show()
        utime.sleep(2)
        wri.printstring('\nCount = {:2d}'.format(x))
    ssd.show()
    utime.sleep(2)
    wri.printstring('\nDone.')
    ssd.show()
    CWriter.invert_display(ssd, False)  # For subsequent tests 
开发者ID:peterhinch,项目名称:micropython-font-to-py,代码行数:22,代码来源:writer_tests.py

示例3: multi_fields

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def multi_fields(t):
    print('Dynamic labels.')
    refresh(ssd, True)  # Clear any prior image
    nfields = []
    dy = wri.height + 6
    y = 2
    col = 15
    width = wri.stringlen('99.99')
    for txt in ('X:', 'Y:', 'Z:'):
        Label(wri, y, 0, txt)  # Use wri default colors
        nfields.append(Label(wri, y, col, width, bdcolor=None))  # Specify a border, color TBD
        y += dy

    end = utime.ticks_add(utime.ticks_ms(), t * 1000)
    while utime.ticks_diff(end, utime.ticks_ms()) > 0:
        for field in nfields:
            value = int.from_bytes(uos.urandom(3),'little')/167772
            overrange =  None if value < 70 else YELLOW if value < 90 else RED
            field.value('{:5.2f}'.format(value), fgcolor = overrange, bdcolor = overrange)
        refresh(ssd)
        utime.sleep(1)
    Label(wri, 0, 64, ' OK ', True, fgcolor = RED)
    refresh(ssd)
    utime.sleep(1) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:26,代码来源:color15.py

示例4: multi_fields

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def multi_fields(t):
    print('multi_fields')
    refresh(ssd, True)  # Clear any prior image
    nfields = []
    dy = wri.height + 6
    y = 2
    col = 15
    width = wri.stringlen('99.99')
    for txt in ('X:', 'Y:', 'Z:'):
        Label(wri, y, 0, txt)  # Use wri default colors
        nfields.append(Label(wri, y, col, width, bdcolor=None))  # Specify a border, color TBD
        y += dy

    end = utime.ticks_add(utime.ticks_ms(), t * 1000)
    while utime.ticks_diff(end, utime.ticks_ms()) > 0:
        for field in nfields:
            value = int.from_bytes(uos.urandom(3),'little')/167772
            overrange =  None if value < 70 else YELLOW if value < 90 else RED
            field.value('{:5.2f}'.format(value), fgcolor = overrange, bdcolor = overrange)
        refresh(ssd)
        utime.sleep(1)
    Label(wri, 0, 64, ' OK ', True, fgcolor = RED)
    refresh(ssd)
    utime.sleep(1) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:26,代码来源:color96.py

示例5: fields

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def fields(use_spi=False, soft=True):
    ssd = setup(use_spi, soft)  # Create a display instance
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, fixed, verbose=False)
    wri.set_clip(False, False, False)
    textfield = Label(wri, 0, 2, wri.stringlen('longer'))
    numfield = Label(wri, 25, 2, wri.stringlen('99.99'), bdcolor=None)
    countfield = Label(wri, 0, 90, wri.stringlen('1'))
    n = 1
    for s in ('short', 'longer', '1', ''):
        textfield.value(s)
        numfield.value('{:5.2f}'.format(int.from_bytes(uos.urandom(2),'little')/1000))
        countfield.value('{:1d}'.format(n))
        n += 1
        refresh(ssd)
        utime.sleep(2)
    textfield.value('Done', True)
    refresh(ssd) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:20,代码来源:mono_test.py

示例6: multi_fields

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def multi_fields(use_spi=False, soft=True):
    ssd = setup(use_spi, soft)  # Create a display instance
    Writer.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = Writer(ssd, small, verbose=False)
    wri.set_clip(False, False, False)

    nfields = []
    dy = small.height() + 6
    y = 2
    col = 15
    width = wri.stringlen('99.99')
    for txt in ('X:', 'Y:', 'Z:'):
        Label(wri, y, 0, txt)
        nfields.append(Label(wri, y, col, width, bdcolor=None))  # Draw border
        y += dy

    for _ in range(10):
        for field in nfields:
            value = int.from_bytes(uos.urandom(3),'little')/167772
            field.value('{:5.2f}'.format(value))
        refresh(ssd)
        utime.sleep(1)
    Label(wri, 0, 64, ' DONE ', True)
    refresh(ssd) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:26,代码来源:mono_test.py

示例7: wifi_connect

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def wifi_connect(essid, password):
    # Connect to the wifi. Based on the example in the micropython
    # documentation.
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network ' + essid + '...')
        wlan.connect(essid, password)
        # connect() appears to be async - waiting for it to complete
        while not wlan.isconnected():
            print('waiting for connection...')
            utime.sleep(4)
            print('checking connection...')
        print('Wifi connect successful, network config: %s' % repr(wlan.ifconfig()))
    else:
        # Note that connection info is stored in non-volatile memory. If
        # you are connected to the wrong network, do an explicity disconnect()
        # and then reconnect.
        print('Wifi already connected, network config: %s' % repr(wlan.ifconfig())) 
开发者ID:mpi-sws-rse,项目名称:thingflow-python,代码行数:21,代码来源:wifi.py

示例8: suspend

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def suspend():
    for x in range(10, 0, -1):
        print('nunning', x)
        utime.sleep(0.5)
        wdt_feed(5)  # Hold off for 5s

    wdt_feed(WDT_SUSPEND)
    for x in range(5, 0, -1):
        print('suspended', x)
        utime.sleep(0.5)

    for x in range(5, 0, -1):
        print('nunning', x)
        utime.sleep(0.5)
        wdt_feed(5)  # Hold off for 5s

    print('Should reset in 5s')
    utime.sleep(10)
    wdt_feed(WDT_CANCEL)  # Should never execute

# Default period 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:23,代码来源:swdt_tests.py

示例9: find_heart_rate

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def find_heart_rate(self):
        """ """
        adv = self.bt.get_adv()
        if adv and self.bt.resolve_adv_data(adv.data, Bluetooth.ADV_NAME_CMPL) == 'Heart Rate':
            try:
                conn = self.bt.connect(adv.mac, timeout=5000)
                services = conn.services()
                for service in services:
                    utime.sleep(0.050)
                    if type(service.uuid()) == bytes:
                        print('Reading chars from service = {}'.format(service.uuid()))
                    else:
                        print('Reading chars from service = %x' % service.uuid())
                    chars = service.characteristics()
                    for char in chars:
                        if (char.properties() & Bluetooth.PROP_READ):
                            print('char {} value = {}'.format(char.uuid(), char.read()))
                conn.disconnect()
            except:
                print("Error while connecting or reading from the BLE device")
        else:
            utime.sleep(0.050)

        utime.sleep(10.0) 
开发者ID:hiveeyes,项目名称:terkin-datalogger,代码行数:26,代码来源:pycom.py

示例10: dual

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def dual(use_spi=False, soft=True):
    ssd0 = setup(False, soft)  # I2C display
    ssd1 = setup(True, False)  # SPI  instance
    Writer.set_textpos(ssd0, 0, 0)  # In case previous tests have altered it
    wri0 = Writer(ssd0, small, verbose=False)
    wri0.set_clip(False, False, False)
    Writer.set_textpos(ssd1, 0, 0)  # In case previous tests have altered it
    wri1 = Writer(ssd1, small, verbose=False)
    wri1.set_clip(False, False, False)

    nfields = []
    dy = small.height() + 6
    col = 15
    for n, wri in enumerate((wri0, wri1)):
        nfields.append([])
        y = 2
        for txt in ('X:', 'Y:', 'Z:'):
            Label(wri, y, 0, txt)
            nfields[n].append(Label(wri, y, col, wri.stringlen('99.99'), True))
            y += dy

    for _ in range(10):
        for n, wri in enumerate((wri0, wri1)):
            for field in nfields[n]:
                value = int.from_bytes(uos.urandom(3),'little')/167772
                field.value('{:5.2f}'.format(value))
            wri.device.show()
            utime.sleep(1)
    for wri in (wri0, wri1):
        Label(wri, 0, 64, ' DONE ', True)
        wri.device.show() 
开发者ID:peterhinch,项目名称:micropython-font-to-py,代码行数:33,代码来源:writer_tests.py

示例11: meter

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def meter():
    print('Meter test.')
    refresh(ssd, True)  # Clear any prior image
    color = lambda v : RED if v > 0.7 else YELLOW if v > 0.5 else GREEN
    txt = lambda v : 'ovr' if v > 0.7 else 'high' if v > 0.5 else 'ok'
    m0 = Meter(wri, 5, 2, divisions = 4, ptcolor=YELLOW,
              label='left', style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
    l0 = LED(wri, ssd.height - 16 - wri.height, 2, bdcolor=YELLOW, label ='over')
    m1 = Meter(wri, 5, 50, divisions = 4, ptcolor=YELLOW,
              label='right', style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
    l1 = LED(wri, ssd.height - 16 - wri.height, 50, bdcolor=YELLOW, label ='over')
    m2 = Meter(wri, 5, 98, divisions = 4, ptcolor=YELLOW,
              label='bass', style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
    l2 = LED(wri, ssd.height - 16 - wri.height, 98, bdcolor=YELLOW, label ='over')
    steps = 10
    for n in range(steps):
        v = int.from_bytes(uos.urandom(3),'little')/16777216
        m0.value(v, color(v))
        l0.color(color(v))
        l0.text(txt(v), fgcolor=color(v))
        v = n/steps
        m1.value(v, color(v))
        l1.color(color(v))
        l1.text(txt(v), fgcolor=color(v))
        v = 1 - n/steps
        m2.value(v, color(v))
        l2.color(color(v))
        l2.text(txt(v), fgcolor=color(v))
        refresh(ssd)
        utime.sleep(1) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:32,代码来源:color15.py

示例12: vari_fields

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def vari_fields():
    print('Variable label styles.')
    refresh(ssd, True)  # Clear any prior image
    wri_large = CWriter(ssd, freesans20, GREEN, BLACK, verbose=False)
    wri_large.set_clip(True, True, False)
    Label(wri_large, 0, 0, 'Text')
    Label(wri_large, 20, 0, 'Border')
    width = wri_large.stringlen('Yellow')
    lbl_text = Label(wri_large, 0, 65, width)
    lbl_bord = Label(wri_large, 20, 65, width)
    lbl_text.value('Red')
    lbl_bord.value('Red')
    lbl_var = Label(wri_large, 50, 2, '25.46', fgcolor=RED, bdcolor=RED)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('Yellow')
    lbl_var.value(bdcolor=YELLOW)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Red')
    lbl_bord.value('None')
    lbl_var.value(bdcolor=False)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Yellow')
    lbl_bord.value('None')
    lbl_var.value(fgcolor=YELLOW)
    refresh(ssd)
    utime.sleep(2)
    lbl_text.value('Blue')
    lbl_bord.value('Green')
    lbl_var.value('18.99', fgcolor=BLUE, bdcolor=GREEN)
    Label(wri, ssd.height - wri.height - 2, 0, 'Done', fgcolor=RED)
    refresh(ssd) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:37,代码来源:color15.py

示例13: meter

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def meter():
    print('meter')
    refresh(ssd, True)  # Clear any prior image
    m = Meter(wri, 5, 2, height = 45, divisions = 4, ptcolor=YELLOW,
              label='level', style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
    l = LED(wri, 5, 40, bdcolor=YELLOW, label ='over')
    steps = 10
    for _ in range(steps):
        v = int.from_bytes(uos.urandom(3),'little')/16777216
        m.value(v)
        l.color(GREEN if v < 0.5 else RED)
        refresh(ssd)
        utime.sleep(1)
    refresh(ssd) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:16,代码来源:color96.py

示例14: meter

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def meter(use_spi=False, soft=True):
    ssd = setup(use_spi, soft)
    wri = Writer(ssd, arial10, verbose=False)
    ssd.fill(0)
    refresh(ssd)
    m0 = Meter(wri, 5, 2, height = 50, divisions = 4, legends=('0.0', '0.5', '1.0'))
    m1 = Meter(wri, 5, 44, height = 50, divisions = 4, legends=('-1', '0', '+1'))
    m2 = Meter(wri, 5, 86, height = 50, divisions = 4, legends=('-1', '0', '+1'))
    steps = 10
    for n in range(steps + 1):
        m0.value(int.from_bytes(uos.urandom(3),'little')/16777216)
        m1.value(n/steps)
        m2.value(1 - n/steps)
        refresh(ssd)
        utime.sleep(1) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:17,代码来源:mono_test.py

示例15: aclock

# 需要导入模块: import utime [as 别名]
# 或者: from utime import sleep [as 别名]
def aclock():
    uv = lambda phi : cmath.rect(1, phi)  # Return a unit vector of phase phi
    pi = cmath.pi
    days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
            'Sunday')
    months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July',
              'Aug', 'Sept', 'Oct', 'Nov', 'Dec')
    # Instantiate CWriter
    CWriter.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
    wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
    wri.set_clip(True, True, False)

    # Instantiate displayable objects
    dial = Dial(wri, 2, 2, height = 75, ticks = 12, bdcolor=None, label=120, pip=False)  # Border in fg color
    lbltim = Label(wri, 5, 85, 35)
    hrs = Pointer(dial)
    mins = Pointer(dial)
    secs = Pointer(dial)

    hstart =  0 + 0.7j  # Pointer lengths and position at top
    mstart = 0 + 0.92j
    sstart = 0 + 0.92j 
    while True:
        t = utime.localtime()
        hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW)
        mins.value(mstart * uv(-t[4] * pi/30), YELLOW)
        secs.value(sstart * uv(-t[5] * pi/30), RED)
        lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5]))
        dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0]))
        refresh(ssd)
        utime.sleep(1) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:33,代码来源:aclock.py


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