本文整理汇总了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)
示例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))
示例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)
示例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)
示例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)
示例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()
示例7: __init__
# 需要导入模块: import pyb [as 别名]
# 或者: from pyb import Switch [as 别名]
def __init__(self):
self.sw = pyb.Switch()
示例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