Skip to content

Instantly share code, notes, and snippets.

@mipsparc mipsparc/sekkin.py

Created Aug 3, 2019
Embed
What would you like to do?
接近メロディーながすやつ
#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
You can’t perform that action at this time.