Skip to content

Commit e4f6230

Browse files
authored
Merge pull request #545 from adafruit/Basic_Resistor_Sensor_Reading_on_Raspberry_Pi
Basic resistor sensor reading on raspberry pi
2 parents c7bdbbf + 37fcfe2 commit e4f6230

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Example for RC timing reading for Raspberry Pi
2+
# using CircuitPython Libraries
3+
4+
import time
5+
import board
6+
from digitalio import DigitalInOut, Direction
7+
8+
RCpin = board.D18
9+
10+
while True:
11+
with DigitalInOut(RCpin) as rc:
12+
reading = 0
13+
14+
# setup pin as output and direction low value
15+
rc.direction = Direction.OUTPUT
16+
rc.value = False
17+
18+
time.sleep(0.1)
19+
20+
# setup pin as input and wait for low value
21+
rc.direction = Direction.INPUT
22+
23+
# This takes about 1 millisecond per loop cycle
24+
while rc.value is False:
25+
reading += 1
26+
print(reading)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Basic_Resistor_Sensor_Reading_on_Raspberry_Pi
2+
3+
Code to accompany this tutorial:
4+
https://learn.adafruit.com/basic-resistor-sensor-reading-on-raspberry-pi

0 commit comments

Comments
 (0)