當前位置: 首頁>>代碼示例>>Python>>正文


Python pyb.Switch方法代碼示例

本文整理匯總了Python中pyb.Switch方法的典型用法代碼示例。如果您正苦於以下問題:Python pyb.Switch方法的具體用法?Python pyb.Switch怎麽用?Python pyb.Switch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyb的用法示例。


在下文中一共展示了pyb.Switch方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Switch [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

示例2: main

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Switch [as 別名]
def main():
    sw_state = False
    led = pyb.LED(1)
    switch = pyb.Switch()
    switch.callback(set_sw_state)
    accel = STAccel()
    hid = pyb.USB_HID()

    while True:
        if sw_state:
            x, y, z = accel.xyz()
            hid.send((0, int(x * MAG), int(-y * MAG), 0))

        pyb.delay(int(1000 / FREQ)) 
開發者ID:SpotlightKid,項目名稱:micropython-stm-lib,代碼行數:16,代碼來源:accelmouse.py

示例3: main

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Switch [as 別名]
def main():
    import pyb

    serial = pyb.USB_VCP()
    midi = MidiOut(serial, channel=1)
    switch = pyb.Switch()

    if hasattr(pyb, 'Accel'):
        accel = pyb.Accel()
        SCALE = 1.27
    else:
        from staccel import STAccel
        accel = STAccel()
        SCALE = 127

    while True:
        while not switch():
            pyb.delay(10)

        note = abs(int(accel.x() * SCALE))
        velocity = abs(int(accel.y() * SCALE))
        midi.note_on(note, velocity)

        while switch():
            pyb.delay(50)

        midi.note_off(note) 
開發者ID:SpotlightKid,項目名稱:micropython-stm-lib,代碼行數:29,代碼來源:accelusbmidi.py

示例4: main

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Switch [as 別名]
def main():
    switch = Switch()

    while not switch():
        delay(200)

    # Initialize UART for MIDI
    uart = UART(2, baudrate=31250)
    midi = MidiOut(uart)
    seq = Sequencer(midi, bpm=124)
    seq.play(Pattern(PATTERN), kit=9) 
開發者ID:SpotlightKid,項目名稱:micropython-stm-lib,代碼行數:13,代碼來源:mididrumbox.py

示例5: main

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Switch [as 別名]
def main():
    # Initialize UART for MIDI
    uart = UART(2, baudrate=31250)
    midi = MidiOut(uart)
    button1 = Switch()
    button2 = Pin('PC0', Pin.IN, Pin.PULL_UP)
    button3 = Pin('PC1', Pin.IN, Pin.PULL_UP)
    led1 = LED(1)
    led2 = LED(2)
    led3 = LED(3)
    tune = program = 0

    # send a PROGRAM CHANGE to set instrument to #0 (Grand Piano)
    midi.program_change(program)

    while True:
        if button1():
            # When button 1 is pressed, play the current tune
            play(midi, TUNES[TUNENAMES[tune]], led1)
            led1.off()
        if not button2():
            # When button 2 is pressed, select the next of the tunes
            led2.on()
            tune = (tune+1) % len(TUNENAMES)
            delay(BLINK_DELAY)
            led2.off()
        if not button3():
            # When button 3 is pressed, change to next program (instrument)
            led3.on()
            program = (program+1) % len(PROGRAMS)
            midi.program_change(PROGRAMS[program])
            delay(BLINK_DELAY)
            led3.off()

        delay(200) 
開發者ID:SpotlightKid,項目名稱:micropython-stm-lib,代碼行數:37,代碼來源:midiplay.py

示例6: killer

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Switch [as 別名]
def killer(tasks):
    sw = pyb.Switch()
    while not sw():
        await asyncio.sleep_ms(100)
    for task in tasks:
        task.cancel() 
開發者ID:peterhinch,項目名稱:micropython-nano-gui,代碼行數:8,代碼來源:asnano.py

示例7: __init__

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Switch [as 別名]
def __init__(self):
        self.sw = pyb.Switch() 
開發者ID:peterhinch,項目名稱:micropython-nano-gui,代碼行數:4,代碼來源:asnano_sync.py

示例8: sw

# 需要導入模塊: import pyb [as 別名]
# 或者: from pyb import Switch [as 別名]
def sw():
    return not switch.value()
# Code for Pyboard switch
#sw = pyb.Switch()

# Choose test to run 
開發者ID:micropython-IMU,項目名稱:micropython-fusion,代碼行數:8,代碼來源:fusiontest.py


注:本文中的pyb.Switch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。