bananenkeyboard/Pi/s.py

39 lines
1.4 KiB
Python
Executable File

#!/usr/bin/python3
import serial
import pygame
pygame.mixer.pre_init(buffer=32)
pygame.init()
pygame.mixer.quit()
pygame.mixer.init(buffer=32)
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)
oldrcv = port.read()
while True:
# 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