Skip to content

Commit 37fcfe2

Browse files
author
Mikey Sklar
committed
swapped function for with ... rc as and removed duplicate pin init
1 parent 29b9036 commit 37fcfe2

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

Basic_Resistor_Sensor_Reading_on_Raspberry_Pi/Basic_Resistor_Sensor_Reading_on_Raspberry_Pi.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,22 @@
55
import board
66
from digitalio import DigitalInOut, Direction
77

8-
def RCtime (RCpin):
9-
reading = 0
8+
RCpin = board.D18
109

11-
# setup pin as output and direction low value
12-
rc = DigitalInOut(RCpin)
13-
rc.direction = Direction.OUTPUT
14-
rc.value = False
10+
while True:
11+
with DigitalInOut(RCpin) as rc:
12+
reading = 0
1513

16-
time.sleep(0.1)
14+
# setup pin as output and direction low value
15+
rc.direction = Direction.OUTPUT
16+
rc.value = False
1717

18-
# setup pin as input and wait for low value
19-
rc = DigitalInOut(RCpin)
20-
rc.direction = Direction.INPUT
18+
time.sleep(0.1)
2119

22-
# This takes about 1 millisecond per loop cycle
23-
while rc.value is False:
24-
reading += 1
25-
return reading
20+
# setup pin as input and wait for low value
21+
rc.direction = Direction.INPUT
2622

27-
while True:
28-
result = RCtime(board.D18) # Read RC timing using pin #18
29-
print(result)
23+
# This takes about 1 millisecond per loop cycle
24+
while rc.value is False:
25+
reading += 1
26+
print(reading)

0 commit comments

Comments
 (0)