Umstellung auf die Gitarre

This commit is contained in:
starcalc 2020-06-29 23:11:07 +01:00
parent 22dff602bb
commit 04343fa68e
1 changed files with 22 additions and 10 deletions

32
Pi/s.py
View File

@ -8,36 +8,48 @@ 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') #SoundC = pygame.mixer.Sound('ogg/C3v16.ogg')
SoundA = pygame.mixer.Sound('ogg/A3v16.ogg') #SoundA = pygame.mixer.Sound('ogg/A3v16.ogg')
SoundFF = pygame.mixer.Sound('ogg/F#3v16.ogg') #SoundFF = pygame.mixer.Sound('ogg/F#3v16.ogg')
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')
# port = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=.001) # 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) # port = serial.Serial("/dev/ttyAMA0", baudrate=115200)
SoundA.play();
oldrcv = port.read() oldrcv = port.read()
while True: while True:
# rcv decodieren # rcv decodieren
rcv = port.read() rcv = port.read()
# 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.
if rcv[0] & ( 1 << 2 ) :
if not oldrcv[0] & ( 1 << 2 ):
print("1");
SoundE.stop()
SoundE.play()
else:
SoundE.stop()
rcvstate0 = False
if rcv[0] & ( 1 << 1 ) : if rcv[0] & ( 1 << 1 ) :
if not oldrcv[0] & ( 1 << 1 ): if not oldrcv[0] & ( 1 << 1 ):
print("1"); print("1");
SoundC.stop() SoundD.stop()
SoundC.play() SoundD.play()
else: else:
SoundC.stop() SoundD.stop()
rcvstate0 = False rcvstate0 = False
if rcv[0] & ( 1 << 0 ) : if rcv[0] & ( 1 << 0 ) :
if not oldrcv[0] & ( 1 << 0 ): if not oldrcv[0] & ( 1 << 0 ):
print("0"); print("0");
SoundA.stop() SoundC.stop()
SoundA.play() SoundC.play()
else: else:
SoundA.stop() SoundC.stop()
oldrcv = rcv oldrcv = rcv