swapped function for with ... rc as and removed duplicate pin init
@@ -5,25 +5,22 @@ import time
import board
from digitalio import DigitalInOut, Direction
-def RCtime (RCpin):
+RCpin = board.D18
+
+while True:
+ with DigitalInOut(RCpin) as rc:
reading = 0
# setup pin as output and direction low value
- rc = DigitalInOut(RCpin)
rc.direction = Direction.OUTPUT
rc.value = False
time.sleep(0.1)
# setup pin as input and wait for low value
- rc = DigitalInOut(RCpin)
rc.direction = Direction.INPUT
# This takes about 1 millisecond per loop cycle
while rc.value is False:
reading += 1
- return reading
-
-while True:
- result = RCtime(board.D18) # Read RC timing using pin #18
- print(result)
+ print(reading)
