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


Python PyMata.play_tone方法代码示例

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


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

示例1: PyMata

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import play_tone [as 别名]
from PyMata.pymata import PyMata


BEEPER = 3  # pin that piezo device is attached to

# create a PyMata instance
board = PyMata("/dev/ttyACM0")


def signal_handler(sig, frm):
    print('You pressed Ctrl+C!!!!')
    if board is not None:
        board.reset()
    sys.exit(0)


signal.signal(signal.SIGINT, signal_handler)

board.play_tone(BEEPER, board.TONE_TONE, 1000, 500)
time.sleep(2)

# play a continuous tone, wait 3 seconds and then turn tone off
board.play_tone(BEEPER, board.TONE_TONE, 1000, 0)
time.sleep(3)
board.play_tone(BEEPER, board.TONE_NO_TONE, 1000, 0)

board.close()


开发者ID:MrYsLab,项目名称:PyMata,代码行数:29,代码来源:piezo_beep.py

示例2:

# 需要导入模块: from PyMata.pymata import PyMata [as 别名]
# 或者: from PyMata.pymata.PyMata import play_tone [as 别名]
time.sleep(.2)
print firmata.analog_read(POTENTIOMETER)

# set the button switch as a digital input
firmata.set_pin_mode(BUTTON_SWITCH, firmata.INPUT, firmata.DIGITAL)

# wait for the button switch to be pressed

while not firmata.digital_read(BUTTON_SWITCH):
    time.sleep(.1)
    pass
print firmata.digital_read(BUTTON_SWITCH)

# send out a beep in celebration of detecting the button press
# note that you don't need to set pin mode for play_tone
firmata.play_tone(BEEPER, firmata.TONE_TONE, 1000, 500)

# control the servo - note that you don't need to set pin mode
# configure the servo
firmata.servo_config(SERVO_MOTOR)

# move the servo to 20 degrees
firmata.analog_write(SERVO_MOTOR, 20)
time.sleep(.5)

# move the servo to 100 degrees
firmata.analog_write(SERVO_MOTOR, 100)
time.sleep(.5)

# move the servo to 20 degrees
firmata.analog_write(SERVO_MOTOR, 20)
开发者ID:ChrisNolan,项目名称:PyMata,代码行数:33,代码来源:pymata_basics.py


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