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


Python pyb.LED属性代码示例

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


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

示例1: led_angle

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def led_angle():
    # make LED objects
    l1 = pyb.LED(1)
    l2 = pyb.LED(2)
    accel = STAccel()

    while True:
        # get x-axis
        x = accel.x() * 50

        # turn on LEDs depending on angle
        if x < -10:
            l2.on()
            l1.off()
        elif x > 10:
            l1.on()
            l2.off()
        else:
            l1.off()
            l2.off()

        # delay so that loop runs at at 1/50ms = 20Hz
        pyb.delay(50) 
开发者ID:SpotlightKid,项目名称:micropython-stm-lib,代码行数:25,代码来源:accelleds.py

示例2: main

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def main():
    print('Press Pyboard usr button to stop test.')
    # Asynchronously flash Pyboard LED's. Because we can.
    leds = [asyncio.create_task(flash(1, 200)), asyncio.create_task(flash(2, 233))]
    # Task for each meter and GUI LED
    mtasks =[MyMeter(2, 'left').task, MyMeter(50, 'right').task, MyMeter(98, 'bass').task]
    k = Killer()
    while True:
        if await k.wait(800):  # Switch was pressed
            break
        refresh(ssd)
    for task in mtasks + leds:
        task.cancel()
    await asyncio.sleep_ms(0)
    ssd.fill(0)  # Clear display at end.
    refresh(ssd) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:18,代码来源:asnano_sync.py

示例3: test_sw

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def test_sw():
    s = '''
close pulses green
open pulses red
'''
    print('Test of switch scheduling coroutines.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    sw = Switch(pin)
    # Register coros to launch on contact close and open
    sw.close_func(pulse, (green, 1000))
    sw.open_func(pulse, (red, 1000))
    loop = asyncio.get_event_loop()
    loop.run_until_complete(killer())

# Test for the switch class with a callback 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:21,代码来源:switches.py

示例4: test_swcb

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def test_swcb():
    s = '''
close toggles red
open toggles green
'''
    print('Test of switch executing callbacks.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    sw = Switch(pin)
    # Register a coro to launch on contact close
    sw.close_func(toggle, (red,))
    sw.open_func(toggle, (green,))
    loop = asyncio.get_event_loop()
    loop.run_until_complete(killer())

# Test for the Pushbutton class (coroutines)
# Pass True to test suppress 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:22,代码来源:switches.py

示例5: test_btncb

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def test_btncb():
    s = '''
press toggles red
release toggles green
double click toggles yellow
long press toggles blue
'''
    print('Test of pushbutton executing callbacks.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    yellow = LED(3)
    blue = LED(4)
    pb = Pushbutton(pin)
    pb.press_func(toggle, (red,))
    pb.release_func(toggle, (green,))
    pb.double_func(toggle, (yellow,))
    pb.long_func(toggle, (blue,))
    loop = asyncio.get_event_loop()
    loop.run_until_complete(killer()) 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:24,代码来源:switches.py

示例6: cb

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def cb(data, addr, led):
    if addr == 0x40:  # Adapt for your remote
        if data == 1:  # Button 1. Adapt for your remote/buttons
            print('LED on')
            if platform == 'pyboard':
                led.on()
            else:
                led(0)
        elif data == 2:
            print('LED off')
            if platform == 'pyboard':
                led.off()
            else:
                led(1)
        elif data < REPEAT:
            print('Bad IR data')
    else:
        print('Incorrect remote') 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:20,代码来源:art1.py

示例7: test

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def test():
    print('Test for IR receiver. Assumes NEC protocol. Turn LED on or off.')
    if platform == 'pyboard':
        p = Pin('X3', Pin.IN)
        led = LED(2)
    elif platform == 'esp8266':
        freq(160000000)
        p = Pin(13, Pin.IN)
        led = Pin(2, Pin.OUT)
        led(1)
    elif ESP32:
        p = Pin(23, Pin.IN)
        led = Pin(21, Pin.OUT)  # LED with 220Ω series resistor between 3.3V and pin 21
        led(1)
    ir = NEC_IR(p, cb, True, led)  # Assume extended address mode r/c
    loop = asyncio.get_event_loop()
    loop.run_forever() 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:19,代码来源:art1.py

示例8: test

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def test():
    print('Test for IR receiver. Assumes NEC protocol. Turn LED on or off.')
    if platform == 'pyboard':
        p = Pin('X3', Pin.IN)
        led = LED(2)
    elif platform == 'esp8266':
        freq(160000000)
        p = Pin(13, Pin.IN)
        led = Pin(2, Pin.OUT)
        led(1)
    elif ESP32:
        p = Pin(23, Pin.IN)
        led = Pin(21, Pin.OUT)  # LED with 220Ω series resistor between 3.3V and pin 21
        led(1)
    ir = NEC_IR(p, cb, True, led)  # Assume extended address mode r/c
    loop = asyncio.get_event_loop()
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        print('Interrupted')
    finally:
        asyncio.new_event_loop()  # Still need ctrl-d because of interrupt vector 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:24,代码来源:art1.py

示例9: shutdown

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def shutdown():
    global gps
    # Normally UART is already at BAUDRATE. But if last session didn't restore
    # factory baudrate we can restore connectivity in the subsequent stuck
    # session with ctrl-c.
    uart.init(BAUDRATE)
    await asyncio.sleep(0.5)
    await gps.command(FULL_COLD_START)
    print('Factory reset')
    gps.close()  # Stop ISR
    #print('Restoring default baudrate (9600).')
    #await gps.baudrate(9600)
    #uart.init(9600)
    #gps.close()  # Stop ISR
    #print('Restoring default 1s update rate.')
    #await asyncio.sleep(0.5)
    #await gps.update_interval(1000)  # 1s update rate 
    #print('Restoring satellite data.')
    #await gps.command(as_rwGPS.DEFAULT_SENTENCES)  # Restore satellite data

# Setup for tests. Red LED toggles on fix, blue on PPS interrupt. 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:23,代码来源:as_rwGPS_time.py

示例10: us_setup

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def us_setup(tick):
    global uart, gps  # For shutdown
    red = pyb.LED(1)
    blue = pyb.LED(4)
    sreader = asyncio.StreamReader(uart)
    swriter = asyncio.StreamWriter(uart, {})
    pps_pin = pyb.Pin(PPS_PIN, pyb.Pin.IN)
    gps = GPS_RWTimer(sreader, swriter, pps_pin, local_offset=1,
                             fix_cb=lambda *_: red.toggle(),
                             pps_cb=us_cb, pps_cb_args=(tick, blue))
    gps.FULL_CHECK = False
    await asyncio.sleep(2)
    await gps.baudrate(BAUDRATE)
    uart.init(BAUDRATE)
    await asyncio.sleep(1)
    await gps.enable(gsa=0, gsv=0)  # Disable satellite data
    await gps.update_interval(UPDATE_INTERVAL)
    pstr = 'Baudrate {} update interval {}ms satellite messages disabled.'
    print(pstr.format(BAUDRATE, UPDATE_INTERVAL)) 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:21,代码来源:as_rwGPS_time.py

示例11: test_sw

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def test_sw():
    s = '''
close pulses green
open pulses red
'''
    print('Test of switch scheduling coroutines.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    sw = Switch(pin)
    # Register coros to launch on contact close and open
    sw.close_func(pulse, (green, 1000))
    sw.open_func(pulse, (red, 1000))
    run()

# Test for the switch class with a callback 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:20,代码来源:switches.py

示例12: test_swcb

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def test_swcb():
    s = '''
close toggles red
open toggles green
'''
    print('Test of switch executing callbacks.')
    print(helptext)
    print(s)
    pin = Pin('X1', Pin.IN, Pin.PULL_UP)
    red = LED(1)
    green = LED(2)
    sw = Switch(pin)
    # Register a coro to launch on contact close
    sw.close_func(toggle, (red,))
    sw.open_func(toggle, (green,))
    run()

# Test for the Pushbutton class (coroutines)
# Pass True to test suppress 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:21,代码来源:switches.py

示例13: heartbeat

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def heartbeat(tms):
    if platform == 'pyboard':  # V1.x or D series
        from pyb import LED
        led = LED(1)
    elif platform == 'esp8266':
        from machine import Pin
        led = Pin(2, Pin.OUT, value=1)
    elif platform == 'linux':
        return  # No LED
    else:
        raise OSError('Unsupported platform.')
    while True:
        if platform == 'pyboard':
            led.toggle()
        elif platform == 'esp8266':
            led(not led())
        await asyncio.sleep_ms(tms) 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:19,代码来源:heartbeat.py

示例14: setup

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def setup():
    global uart, gps  # For shutdown
    red = pyb.LED(1)
    blue = pyb.LED(4)
    sreader = asyncio.StreamReader(uart)
    swriter = asyncio.StreamWriter(uart, {})
    pps_pin = pyb.Pin(PPS_PIN, pyb.Pin.IN)
    gps = as_tGPS.GPS_RWTimer(sreader, swriter, pps_pin, local_offset=1,
                             fix_cb=lambda *_: red.toggle(),
                             pps_cb=lambda *_: blue.toggle())
    gps.FULL_CHECK = False
    await asyncio.sleep(2)
    await gps.baudrate(BAUDRATE)
    uart.init(BAUDRATE)
    await asyncio.sleep(1)
    await gps.enable(gsa=0, gsv=0)  # Disable satellite data
    await gps.update_interval(UPDATE_INTERVAL)
    pstr = 'Baudrate {} update interval {}ms satellite messages disabled.'
    print(pstr.format(BAUDRATE, UPDATE_INTERVAL))
    return gps

# Test terminator: task sets the passed event after the passed time. 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:24,代码来源:as_rwGPS_time.py

示例15: us_setup

# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import LED [as 别名]
def us_setup(tick):
    global uart, gps  # For shutdown
    red = pyb.LED(1)
    blue = pyb.LED(4)
    sreader = asyncio.StreamReader(uart)
    swriter = asyncio.StreamWriter(uart, {})
    pps_pin = pyb.Pin(PPS_PIN, pyb.Pin.IN)
    gps = as_tGPS.GPS_RWTimer(sreader, swriter, pps_pin, local_offset=1,
                             fix_cb=lambda *_: red.toggle(),
                             pps_cb=us_cb, pps_cb_args=(tick, blue))
    gps.FULL_CHECK = False
    await asyncio.sleep(2)
    await gps.baudrate(BAUDRATE)
    uart.init(BAUDRATE)
    await asyncio.sleep(1)
    await gps.enable(gsa=0, gsv=0)  # Disable satellite data
    await gps.update_interval(UPDATE_INTERVAL)
    pstr = 'Baudrate {} update interval {}ms satellite messages disabled.'
    print(pstr.format(BAUDRATE, UPDATE_INTERVAL)) 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:21,代码来源:as_rwGPS_time.py


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