swapped function for with ... rc as and removed duplicate pin init

This commit is contained in:
Mikey Sklar 2019-03-02 17:52:35 -07:00
parent 29b903680c
commit 37fcfe28a8

View file

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