bananenkeyboard/Pi/s.py

34 lines
620 B
Python
Raw Normal View History

2020-01-22 23:14:14 +00:00
#!/usr/bin/python3
import serial
import pygame
pygame.mixer.pre_init(buffer=32)
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')
# port = serial.Serial("/dev/ttyS0", baudrate=115200, timeout=.001)
port = serial.Serial("/dev/ttyS0", baudrate=115200)
while True:
# rcv decodieren
rcv = port.read()
if rcv[0] & ( 1 << 1 ) :
SoundC.stop()
SoundC.play()
else:
SoundC.stop()
if rcv[0] & ( 1 << 2 ) :
SoundA.stop()
SoundA.play()
else:
SoundA.stop()