本文整理汇总了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()
示例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)