Created
June 9, 2018 14:03
-
-
Save mipsparc/8a7223c69cbba6636f16d713a00b63bd to your computer and use it in GitHub Desktop.
https://gist.github.com/mipsparc/f2674a6abda841ef822ad3fc306dd514 から送信されたデータを受け取って表示する
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 | |
device = '/dev/ttyUSB0' | |
ser = serial.Serial(device, baudrate=9600) | |
mascon_level = -1 # init | |
static_mascon_level = -1 # init | |
buttons = -1; | |
same_count = 0; | |
while True: | |
r = ser.read() | |
mascon_new_level = ord(r) & 0b00001111 # 下位4bit | |
same_count += 1 | |
if mascon_new_level != mascon_level: | |
same_count = 0 | |
mascon_level = mascon_new_level | |
if same_count == 3 and static_mascon_level != mascon_level: | |
static_mascon_level = mascon_level | |
print(str(mascon_level) + ' ノッチ') | |
buttons_new = ord(r) >> 4 | |
if buttons_new != buttons: | |
buttons = buttons_new | |
#print('ボタン状態: ' + bytes(buttons)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment