-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistance.py
49 lines (40 loc) · 1.15 KB
/
distance.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
import serial
import codecs
import time
import playsound
import os
def beep(gap):
for i in range(3):
#playsound.playsound('assets/buk.mp3', True)
playsound.playsound('assets/buk.mp3', True)
time.sleep(gap)
usbport = '/dev/ttyACM0' #usb from arduino
arduino = serial.Serial(usbport, 9600, timeout=0)
numbers=list("1234567890")
while (True):
if (arduino.inWaiting()>0):
myData = arduino.readlines()
myDist = myData[len(myData)-1]
list_byt = list(str(myDist))
list_num = []
for _ in list_byt:
if _ in numbers:
list_num.append(_)
else:
pass
#print(list_num)
s = [str(integer) for integer in list_num]
a_string = "".join(s)
print(a_string)
res = int(a_string)
print(res)
time.sleep(0.5)
if res < 10:
beep(0.1)
elif res < 30:
beep(0.4)
elif res < 50:
beep(0.6)
else:
pass
# print(type(res))