Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
https://gist.github.com/mipsparc/f2674a6abda841ef822ad3fc306dd514 から送信されたデータを受け取って表示する
#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
You can’t perform that action at this time.