bananenkeyboard/Pi/s.py

39 lines
1.4 KiB
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)
2022-01-15 12:27:26 +00:00
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')
]
2020-01-22 23:14:14 +00:00
port = serial.Serial("/dev/ttyS0", baudrate=115200)
2020-06-29 21:41:53 +00:00
oldrcv = port.read()
2020-01-22 23:14:14 +00:00
while True:
2022-01-15 12:27:26 +00:00
# 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
2020-01-22 23:14:14 +00:00
2022-01-15 12:27:26 +00:00
oldrcv = rcv