/
butil.py
57 lines (54 loc) · 1.41 KB
/
butil.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
""" SMARS Bluetooth test utility """
import time
import serial
CONNECTED = False
print("Start")
try:
PORT = "/dev/tty.HC-05-SPPDev"
BLUETOOTH = serial.Serial(PORT, 9600, timeout = 1)
print (BLUETOOTH)
print("connected")
CONNECTED = True
except:
print("Error connecting to Bluetooth port: " + PORT)
DELAY = 2
if CONNECTED:
NB = "1"
while NB != "q":
# BLUETOOTH.open()
NB = ""
NB = input('WASD: ')
if NB == "w":
BLUETOOTH.write(b'u') # up
if NB == "s":
BLUETOOTH.write(b'd') # down
if NB == "a":
BLUETOOTH.write(b'l') # left
if NB == "d":
BLUETOOTH.write(b'r') # right
# print (str.encode())
# BLUETOOTH.flushInput()
note = BLUETOOTH.readline()
print(note.decode('ascii'))
# print(str(chr(note)))
time.sleep(DELAY)
# while True:
# BLUETOOTH.write(str.encode('u'))
# print("up")
# time.sleep(DELAY)
# BLUETOOTH.flushInput()
#
# BLUETOOTH.write(str.encode('d'))
# print("down")
# time.sleep(DELAY)
# BLUETOOTH.flushInput()
#
# BLUETOOTH.write(str.encode('l'))
# print("left")
# time.sleep(DELAY)
# BLUETOOTH.flushInput()
#
# BLUETOOTH.write(str.encode('r'))
# print("right")
# time.sleep(DELAY)
# BLUETOOTH.flushInput()