Skip to content

Instantly share code, notes, and snippets.

@mipsparc
Created August 3, 2019 03:48
Show Gist options
  • Save mipsparc/923bbbd9403bd368a03039779c2a420b to your computer and use it in GitHub Desktop.
Save mipsparc/923bbbd9403bd368a03039779c2a420b to your computer and use it in GitHub Desktop.
接近メロディーながすやつ
#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