From f574c2a1894cd6f51675211acc1705275b3ac32f Mon Sep 17 00:00:00 2001 From: starcalc Date: Sat, 15 Jan 2022 13:23:50 +0100 Subject: [PATCH 1/3] Schleife, Komplette Tonleiter --- Pi/s.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Pi/s.py b/Pi/s.py index 8950003..250fdb5 100755 --- a/Pi/s.py +++ b/Pi/s.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 + import serial import pygame From 0f7c74fe78f3e40c84f5ebcad97591c70c1f9d28 Mon Sep 17 00:00:00 2001 From: starcalc Date: Sat, 15 Jan 2022 13:24:15 +0100 Subject: [PATCH 2/3] New version --- Pi/s.py | 59 +++++++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/Pi/s.py b/Pi/s.py index 250fdb5..05bf8b0 100755 --- a/Pi/s.py +++ b/Pi/s.py @@ -1,6 +1,5 @@ #!/usr/bin/python3 - import serial import pygame @@ -12,9 +11,23 @@ pygame.mixer.init(buffer=32) #SoundC = pygame.mixer.Sound('ogg/C3v16.ogg') #SoundA = pygame.mixer.Sound('ogg/A3v16.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') +Sound = [pygame.mixer.Sound('guitar/guitar_C4_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_D4_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_E4_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_F4_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_G4_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) @@ -24,33 +37,17 @@ oldrcv = port.read() while True: # rcv decodieren rcv = port.read() - + i=0 # 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 not oldrcv[0] & ( 1 << 1 ): - print("1"); - SoundD.stop() - SoundD.play() - else: - SoundD.stop() - rcvstate0 = False - - if rcv[0] & ( 1 << 0 ) : - if not oldrcv[0] & ( 1 << 0 ): - print("0"); - SoundC.stop() - SoundC.play() - else: - SoundC.stop() + for cs in Sound: + if rcv[0] & ( 1 << i ) : + if not oldrcv[0] & ( 1 << i ): + print(i) + cs.stop() + cs.play() + i+=1 + else: + cs.stop() + rcvstate0 = False oldrcv = rcv From 12a0d80bbe38b481a32a90b393e8fb352d200f0a Mon Sep 17 00:00:00 2001 From: starcalc Date: Sat, 15 Jan 2022 13:27:26 +0100 Subject: [PATCH 3/3] Loop, Full Sounds --- Pi/s.py | 59 +++++++++++++++++++++------------------------------------ 1 file changed, 22 insertions(+), 37 deletions(-) diff --git a/Pi/s.py b/Pi/s.py index 05bf8b0..2d559c6 100755 --- a/Pi/s.py +++ b/Pi/s.py @@ -8,46 +8,31 @@ pygame.init() pygame.mixer.quit() pygame.mixer.init(buffer=32) -#SoundC = pygame.mixer.Sound('ogg/C3v16.ogg') -#SoundA = pygame.mixer.Sound('ogg/A3v16.ogg') -#SoundFF = pygame.mixer.Sound('ogg/F#3v16.ogg') -Sound = [pygame.mixer.Sound('guitar/guitar_C4_very-long_forte_normal.wav'), - pygame.mixer.Sound('guitar/guitar_D4_very-long_forte_normal.wav'), - pygame.mixer.Sound('guitar/guitar_E4_very-long_forte_normal.wav'), - pygame.mixer.Sound('guitar/guitar_F4_very-long_forte_normal.wav'), - pygame.mixer.Sound('guitar/guitar_G4_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') +Sound = [pygame.mixer.Sound('guitar/guitar_C3_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_D3_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_E3_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_F3_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_G3_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_A3_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_B3_very-long_forte_normal.wav'), + pygame.mixer.Sound('guitar/guitar_C4_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/ttyAMA0", baudrate=115200) oldrcv = port.read() while True: - # rcv decodieren - rcv = port.read() - i=0 - # Zustand merken, und nur "neu" starten, wenn sich etwas von 0 auf 1 veraendert hat. - for cs in Sound: - if rcv[0] & ( 1 << i ) : - if not oldrcv[0] & ( 1 << i ): - print(i) - cs.stop() - cs.play() - i+=1 - else: - cs.stop() - rcvstate0 = False + # rcv decodieren + rcv = port.read() + # Zustand merken, und nur "neu" starten, wenn sich etwas von 0 auf 1 veraendert hat. + for i in range(8): + if rcv[0] & ( 1 << i ) : + if not oldrcv[0] & ( 1 << i ): + Sound[i].stop() + Sound[i].play() + i+=1 + else: + Sound[i].stop() + rcvstate0 = False - oldrcv = rcv + oldrcv = rcv