-
Notifications
You must be signed in to change notification settings - Fork 3
/
demo01.py
44 lines (34 loc) · 1.4 KB
/
demo01.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
#!/usr/bin/env python3
import pygatt
from time import sleep
import ev3dev.ev3 as ev3
adapter = pygatt.GATTToolBackend()
m = ev3.MediumMotor('outA')
DELAY = 0.1
try:
adapter.start()
device = adapter.connect('F5:91:E3:32:23:39',address_type=pygatt.BLEAddressType.random)
device.char_write_handle(0x27, bytearray([0x00, 0x00, 0x00, 0x00, 0x00]))
sleep(DELAY)
device.char_write_handle(0x27, bytearray([0x11, 0x0A, 0x04, 0x0A, 0x11]))
sleep(DELAY)
device.char_write_handle(0x27, bytearray([0x00, 0x0A, 0x04, 0x0A, 0x00]))
sleep(DELAY)
device.char_write_handle(0x27, bytearray([0x00, 0x00, 0x04, 0x00, 0x00]))
sleep(DELAY)
device.char_write_handle(0x27, bytearray([0x00, 0x00, 0x00, 0x00, 0x00]))
sleep(DELAY)
while True:
buttonA = device.char_read("e95dda90-251d-470a-a062-fa1922dfa9a8")
buttonB = device.char_read("e95dda91-251d-470a-a062-fa1922dfa9a8")
if buttonA == bytearray(b'\x01'):
device.char_write_handle(0x27, bytearray([0x04, 0x08, 0x10, 0x08, 0x04]))
m.run_timed(time_sp=100, speed_sp=-500)
elif buttonB == bytearray(b'\x01'):
device.char_write_handle(0x27, bytearray([0x04, 0x02, 0x01, 0x02, 0x04]))
m.run_timed(time_sp=100, speed_sp=500)
else:
device.char_write_handle(0x27, bytearray([0x00, 0x00, 0x00, 0x00, 0x00]))
sleep(0.1)
finally:
adapter.stop()