Created
August 3, 2019 03:48
-
-
Save mipsparc/923bbbd9403bd368a03039779c2a420b to your computer and use it in GitHub Desktop.
接近メロディーながすやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding:utf-8 | |
import serial | |
import time | |
import pygame | |
# シリアルポートのデバイスファイル名に差し替える | |
port = '/dev/sekkin' | |
pygame.mixer.init(44100, -16, 1, 256) | |
sekkin = pygame.mixer.Sound('sounds/sekkin.wav') | |
s = serial.Serial(port, dsrdtr=True) | |
s.dtr = True | |
last_state = False | |
while True: | |
try: | |
state = s.dsr | |
except OSError: | |
print('disconnected') | |
exit() | |
if last_state == False and state == True: | |
sekkin.play(loops=1) | |
last_state = True | |
if state == False: | |
last_state = False | |
time.sleep(0.01) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment