[英]Python, RPi + MCP3008 + 2xForce Sensitive Resistor - Square
I have a MCP3008 connected to RPi and 2 x Force Sensitive Resistor - Square connected to the MCP3008. 我有一个连接到RPi的MCP3008和2个力敏感电阻-方形连接到MCP3008。 The sensors are laying side by side horisontal on my desk and I can read and print the data (0-100) from both sensors (sensor1 and sensor2) separately.
传感器并排放置在我的桌子上,我可以分别读取和打印两个传感器(sensor1和sensor2)的数据(0-100)。 I just can't come up with any idea of python code to detect when I touch sensor1 (left) and move my finger to sensor2 (right).
我只是想不出任何Python代码来检测何时触摸sensor1(左)并将手指移到sensor2(右)。
In addition I need to know how many milliseconds it takes from that I touch sensor1 until I lifted from sensor2. 另外,我需要知道从触摸sensor1到从sensor2提起所花费的毫秒数。
from time import sleep
from gpiozero import MCP3008
sensor1 = MCP3008(1) # Pin 2 on the ADC
sensor2 = MCP3008(2) # Pin 3 on the ADC
# Read data from the ADC
def getData(readSensor):
value = readSensor
rawValue = value.value
return rawValue
while True:
print('Sensor1 = {0:.0f}'.format(getData(sensor1)*100))
print('Sensor2 = {0:.0f}'.format(getData(sensor2)*100))
print('')
sleep(0.1)
You are going to need to timestamp the events and then use the time stamps to determine what action to take. 您将需要为事件加上时间戳,然后使用时间戳来确定要采取的措施。 Something like the below might help you.
如下所示的内容可能会对您有所帮助。
if getData(sensor1) > TOUCH_THRESHOLD:
sensor1LastPressedAt = time.time()
Do the same for sensor2 and compare the time stamps. 对sensor2进行相同的操作,然后比较时间戳。
(TOUCH_THRESHOLD is the value that you measure to be someone touching the button) (TOUCH_THRESHOLD是您测量成为触摸按钮的人的值)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.