File tree Expand file tree Collapse file tree 1 file changed +14
-17
lines changed
Basic_Resistor_Sensor_Reading_on_Raspberry_Pi Expand file tree Collapse file tree 1 file changed +14
-17
lines changed Original file line number Diff line number Diff line change 5
5
import board
6
6
from digitalio import DigitalInOut , Direction
7
7
8
- def RCtime (RCpin ):
9
- reading = 0
8
+ RCpin = board .D18
10
9
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
15
13
16
- time .sleep (0.1 )
14
+ # setup pin as output and direction low value
15
+ rc .direction = Direction .OUTPUT
16
+ rc .value = False
17
17
18
- # setup pin as input and wait for low value
19
- rc = DigitalInOut (RCpin )
20
- rc .direction = Direction .INPUT
18
+ time .sleep (0.1 )
21
19
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
26
22
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 )
You can’t perform that action at this time.
0 commit comments