From 6d50a669a7d2e125714c59176a8435595d67fd38 Mon Sep 17 00:00:00 2001 From: nalbam Date: Wed, 28 Aug 2019 00:42:28 +0900 Subject: [PATCH] tab --- server.js | 2 +- src/pressure.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/pressure.py diff --git a/server.js b/server.js index 4ccc436..b7c5094 100644 --- a/server.js +++ b/server.js @@ -60,7 +60,7 @@ http.listen(port, function () { // gpio gpio.on('change', function (channel, value) { - console.log(`Channel ${channel} value is now ${value} - ${(Math.random() * 100000)}`); + console.log(`Channel ${channel} value is now ${value} \t- ${(Math.random() * 100000)}`); if (channel === 7) { io.sockets.emit('call', 'press'); } else if (channel === 37) { diff --git a/src/pressure.py b/src/pressure.py new file mode 100644 index 0000000..a1ff257 --- /dev/null +++ b/src/pressure.py @@ -0,0 +1,38 @@ +#!/usr/local/bin/python + +import RPi.GPIO as GPIO +import time + +GPIO.setmode(GPIO.BCM) + +# define the pin that goes to the circuit +pin_to_circuit = 4 + + +def rc_time(pin_to_circuit): + count = 0 + + # Output on the pin for + GPIO.setup(pin_to_circuit, GPIO.OUT) + GPIO.output(pin_to_circuit, GPIO.LOW) + time.sleep(0.1) + + # Change the pin back to input + GPIO.setup(pin_to_circuit, GPIO.IN) + + # Count until the pin goes high + while (GPIO.input(pin_to_circuit) == GPIO.LOW): + count += 1 + + return count + + +# Catch when script is interrupted, cleanup correctly +try: + # Main loop + while True: + print(rc_time(pin_to_circuit)) +except KeyboardInterrupt: + pass +finally: + GPIO.cleanup()