我已经使用pi,运动传感器和python构建了一组音乐楼梯,并使用PHP网络应用程序来控制选择哪种乐器。目前,虽然一次只能演奏一个音符,但我想知道是否有一种方法可以更改代码,以便如果一次通过两个运动传感器会产生和弦效果?
import mysql.connector as mariadb # connect to mysql
import RPi.GPIO as GPIO # GPIO
import pygame.mixer # To make sound
GPIO.setmode(GPIO.BCM) # GPIO set mode
GPIO.setwarnings(False)
#Motion sensor setup
GPIO.setup(4, GPIO.IN, GPIO.PUD_UP)
GPIO.setup(17, GPIO.IN, GPIO.PUD_UP)
while True:
#Connect to database
mariadb_connection = mariadb.connect(user='*****', password='*****', database='*****')
cursor = mariadb_connection.cursor()
cursor.execute("SELECT id FROM settings WHERE active = 'true'")
for id in cursor:
print("ID: {}").format(id)
print type(id[0])
input_state = GPIO.input(4)
print("input 4 {}").format(input_state == False)
if input_state == False:
if(id[0]==1):
print "GPIO4 Piano"
C1 = pygame.mixer.Sound("piano/C1.wav")
C1.play()
if(id[0]==2):
print "GPIO4 Drum"
drum1 = pygame.mixer.Sound("drum/Drumc1.wav")
drum1.play()
if(id[0]==3):
print "GPIO4 Xylophone"
X1 = pygame.mixer.Sound("xylophone/X1.wav")
X1.play()
答案 0 :(得分:0)
Mixer一次仅支持一个流。所以用调音台是不可能的
如果您使用Windows,则可以同时使用pygame.mixer和winsound: https://www.youtube.com/watch?v=1FyqFqAN9UM