-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharduino_reader.py
More file actions
51 lines (36 loc) · 1.07 KB
/
arduino_reader.py
File metadata and controls
51 lines (36 loc) · 1.07 KB
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
import serial
import time
#ard_vars = [<pulse>, <gsr>]
def ardThread(port, speed, ard_vars, lock):
global pulse
ser = serial.Serial(port, 115200)
time.sleep(3)
pulses = []
isCalibrating = False
KEYS = "P"
pulse = 0
print('Reader started')
t0 = time.time()
while True:
recv = ser.read().decode('utf-8');
if recv == "P":
num = ''
while True:
recv = ser.read().decode('utf-8')
if recv == 'p':
break
num += recv
pulse = int(num.split('.')[0])
if (time.time() - t0 > 10):
with lock:
ard_vars[0] = pulse
pulses.append(pulse)
t0 = time.time()
with lock:
if ard_vars[3] and not isCalibrating:
print('CALIBRATING\n'*5)
isCalibrating = True
pulses = []
if isCalibrating and not ard_vars[3]:
isCalibrating = False
ard_vars[1] = sum(pulses)/len(pulses)