-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleReadSensor.py
40 lines (29 loc) · 1.03 KB
/
ExampleReadSensor.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
from rangefinders_i2c.ReadSensor import ReadSensor
class ExampleReadSensor:
@staticmethod
def ReadSensorHex():
sensor = ReadSensor(1)
try:
while True:
for address in range(0x18, 0x1e):
distance = sensor.GetDistance(address)
print("address:", address, "distance:", distance)
print("-----------------------------")
except KeyboardInterrupt:
sensor.CloseSMBus()
print("Stopped")
@staticmethod
def ReadSensorInt():
sensor = ReadSensor(1)
try:
while True:
for address in range(24, 30):
distance = sensor.GetDistance(address)
print("address:", address, "distance:", distance)
print("-----------------------------")
except KeyboardInterrupt:
sensor.CloseSMBus()
print("Stopped")
if __name__ == "__main__":
ExampleReadSensor.ReadSensorHex()
ExampleReadSensor.ReadSensorInt()