#!/usr/bin/env python
# Reading capacitive sensor with
# a single GPIO pin
import RPi.GPIO as GPIO, time
# Tell the GPIO library to use
# Broadcom GPIO references
GPIO.setmode(GPIO.BCM)
# Define function to measure charge time
def RCtime (RCpin):
measurement = 0
# Discharge capacitor
GPIO.setup(RCpin, GPIO.OUT)
GPIO.output(RCpin, GPIO.LOW)
time.sleep(0.1)
GPIO.setup(RCpin, GPIO.IN)
# Count loops until voltage across
# capacitor reads high on GPIO
while (GPIO.input(RCpin) == GPIO.LOW):
measurement += 1
return measurement
max=0
min=9999
# Main loop
while True:
value=RCtime(27)
if value > max:
max=value
elif value < min:
min=value
print '{0:3d} {1:3d} {2:3d}'.format(value,min,max)

Código para Latch físico: Touch_calibrate.py

  • 1.
    #!/usr/bin/env python # Readingcapacitive sensor with # a single GPIO pin import RPi.GPIO as GPIO, time # Tell the GPIO library to use # Broadcom GPIO references GPIO.setmode(GPIO.BCM) # Define function to measure charge time def RCtime (RCpin): measurement = 0 # Discharge capacitor GPIO.setup(RCpin, GPIO.OUT) GPIO.output(RCpin, GPIO.LOW) time.sleep(0.1) GPIO.setup(RCpin, GPIO.IN) # Count loops until voltage across # capacitor reads high on GPIO while (GPIO.input(RCpin) == GPIO.LOW): measurement += 1 return measurement max=0 min=9999 # Main loop while True: value=RCtime(27) if value > max: max=value elif value < min: min=value print '{0:3d} {1:3d} {2:3d}'.format(value,min,max)