-
Notifications
You must be signed in to change notification settings - Fork 1
/
bidirectional.py
47 lines (35 loc) · 953 Bytes
/
bidirectional.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
import time
import spidev
pi = spidev.SpiDev()
h = pi.open(0,1)
pi.mode = 0
pi.max_speed_hz =115200
stop = time.time() + 120.0
# data = ['\n','s','s']
# for i in range(len(data)):
# tx = pi.writebytes([ord(data[i])]) #send a single character
while time.time() < stop:
x = pi.readbytes(1)
if (x != 0):
print(x)
# # print(i)
# x = pi.xfer([90]) #send integers/long using an array
# # x = pi.writebytes([90]) #send a single character
# pi.writebytes([ord(['\r'])])
# ports = ["ULTRASONIC","3"]
# portname = ports[0]
# portnumber = str(ports[1])
# portsdict = {
# "LMOTOR" : "LM",
# "RMOTOR" : "RM",
# "MOTOR3" : "M",
# "LINE" : "L",
# "INFARED" : "I",
# "RFID" : "R",
# "ULTRASONIC" : "U"
# }
# arr = ['\n'] + list(portnumber) + list(portsdict[portname]) + ['\r']
# for i in range(len(arr)):
# tx = pi.writebytes([ord(arr[i])]) #send a single character
# print(i)
pi.close()