-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogramrx_py.py
More file actions
82 lines (76 loc) · 2.38 KB
/
programrx_py.py
File metadata and controls
82 lines (76 loc) · 2.38 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# -*- coding: utf-8 -*-
"""Programrx.py
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1MepOshIkepKuxSZK7N1AAQYNp2hD1GnJ
"""
import RPi.GPIO as GPIO
import time
import sys
import re
import csv
from lidar import measure
class rx():
def vlc(self):
while True:
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11, GPIO.IN)
tampung = []
nilainull = 0
ns = 0
jumkar = 1
kartampung = []
with open ('500_30_2.csv','w') as f:
while True:
kondisi = GPIO.input(11)
if kondisi == 1:
while True:
angka = GPIO.input(11)
tampung.append(angka)
if angka == 0:
nilainull = nilainull +1
if angka == 1:
nilainull = 0
if nilainull >=8:
jumkar = len(tampung) / 8
kar = int(jumkar)
jumkar = 8*kar
tampung = tampung[0:jumkar]
ba = 8
bb = 1
for i in range (0,kar):
tampungtemp = tampung[bb:ba]
hasil = "".join(format(x) for x in bytearray(tampungtemp))
kartampung.append(hasil)
ba = ba + 7
bb = bb + 7
try:
kartampung.remove("\x00")
except:
pass
pesan = "{0x08b}".join(format(x) for x in kartampung)
pesan = pesan[0:7]
pesan = re.sub(',!.}{;:', '', pesan)
decimal = 0
timeC = time.strftime("%I")+':'+time.strftime("%M")+':'+time.strftime("%S")
print("Time: ",timeC)
print('pesanterima = ',decimal)
print(pesan)
d = measure(self)
print("Distance(cm): %4d" % d)
thewriter = csv.writer(f)
thewriter.writerow([timeC, d, decimal])
tampung=[]
kartampung=[]
break
time.sleep(.01)
time.sleep(.01)
if __name__ == "__main__":
tes = rx()
tes.vlc()
while True:
timeC = time.strftime("%I")+':'+time.strftime("%M")+':'+time.strftime("%S")
d = measure()
print("Time: ",timeC)
print("Distance(cm): %4d" % d)
time.sleep(0.04)