Loop, Full Sounds

This commit is contained in:
starcalc 2022-01-15 13:27:26 +01:00
parent 0f7c74fe78
commit 12a0d80bbe
1 changed files with 22 additions and 37 deletions

39
Pi/s.py
View File

@ -8,46 +8,31 @@ pygame.init()
pygame.mixer.quit() pygame.mixer.quit()
pygame.mixer.init(buffer=32) pygame.mixer.init(buffer=32)
#SoundC = pygame.mixer.Sound('ogg/C3v16.ogg') Sound = [pygame.mixer.Sound('guitar/guitar_C3_very-long_forte_normal.wav'),
#SoundA = pygame.mixer.Sound('ogg/A3v16.ogg') pygame.mixer.Sound('guitar/guitar_D3_very-long_forte_normal.wav'),
#SoundFF = pygame.mixer.Sound('ogg/F#3v16.ogg') pygame.mixer.Sound('guitar/guitar_E3_very-long_forte_normal.wav'),
Sound = [pygame.mixer.Sound('guitar/guitar_C4_very-long_forte_normal.wav'), pygame.mixer.Sound('guitar/guitar_F3_very-long_forte_normal.wav'),
pygame.mixer.Sound('guitar/guitar_D4_very-long_forte_normal.wav'), pygame.mixer.Sound('guitar/guitar_G3_very-long_forte_normal.wav'),
pygame.mixer.Sound('guitar/guitar_E4_very-long_forte_normal.wav'), pygame.mixer.Sound('guitar/guitar_A3_very-long_forte_normal.wav'),
pygame.mixer.Sound('guitar/guitar_F4_very-long_forte_normal.wav'), pygame.mixer.Sound('guitar/guitar_B3_very-long_forte_normal.wav'),
pygame.mixer.Sound('guitar/guitar_G4_very-long_forte_normal.wav'), pygame.mixer.Sound('guitar/guitar_C4_very-long_forte_normal.wav')
pygame.mixer.Sound('guitar/guitar_A4_very-long_forte_normal.wav'),
pygame.mixer.Sound('guitar/guitar_H4_very-long_forte_normal.wav'),
pygame.mixer.Sound('guitar/guitar_C5_very-long_forte_normal.wav')
] ]
#SoundC = pygame.mixer.Sound('guitar/guitar_C4_very-long_forte_normal.wav')
#SoundD = pygame.mixer.Sound('guitar/guitar_D4_very-long_forte_normal.wav')
#SoundE = pygame.mixer.Sound('guitar/guitar_E4_very-long_forte_normal.wav')
#SoundF = pygame.mixer.Sound('guitar/guitar_F4_very-long_forte_normal.wav')
#SoundG = pygame.mixer.Sound('guitar/guitar_G4_very-long_forte_normal.wav')
#SoundA = pygame.mixer.Sound('guitar/guitar_A4_very-long_forte_normal.wav')
#SoundH = pygame.mixer.Sound('guitar/guitar_H4_very-long_forte_normal.wav')
#SoundC2 = pygame.mixer.Sound('guitar/guitar_C5_very-long_forte_normal.wav')
# port = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=.001)
port = serial.Serial("/dev/ttyS0", baudrate=115200) port = serial.Serial("/dev/ttyS0", baudrate=115200)
# port = serial.Serial("/dev/ttyAMA0", baudrate=115200)
oldrcv = port.read() oldrcv = port.read()
while True: while True:
# rcv decodieren # rcv decodieren
rcv = port.read() rcv = port.read()
i=0
# Zustand merken, und nur "neu" starten, wenn sich etwas von 0 auf 1 veraendert hat. # Zustand merken, und nur "neu" starten, wenn sich etwas von 0 auf 1 veraendert hat.
for cs in Sound: for i in range(8):
if rcv[0] & ( 1 << i ) : if rcv[0] & ( 1 << i ) :
if not oldrcv[0] & ( 1 << i ): if not oldrcv[0] & ( 1 << i ):
print(i) Sound[i].stop()
cs.stop() Sound[i].play()
cs.play()
i+=1 i+=1
else: else:
cs.stop() Sound[i].stop()
rcvstate0 = False rcvstate0 = False
oldrcv = rcv oldrcv = rcv