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