当前位置: 首页>>代码示例>>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;未经允许,请勿转载。