简体   繁体   English

Python,RPi + MCP3008 + 2xForce敏感电阻-正方形

[英]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.

相关问题 Python 使用 MCP3008 采样频率 - Python using MCP3008 sample frequency 无法使用 python 在 rpi0 上设置多个 mcp3008 ADC 芯片。任何关于错误的想法都适用 - Trouble setting up multiple mcp3008 ADC chips on rpi0 using python. Any ideas as to what is wrong are appriciated 使用 Python 在 Raspberry Pi 上以菊花链方式连接 MCP3008 SPI 的问题 - Issue with daisychaining MCP3008 SPI on Raspberry Pi with Python 尝试通过SPI(MCP3304,MCP3204或MCP3008)在RPi 2 b +上读取带有Cython的ADC吗? - Trying to read an ADC with Cython on an RPi 2 b+ via SPI (MCP3304, MCP3204, or MCP3008)? 我可以使用MCP3008输出吗? - could i use a MCP3008 to output? 有什么办法可以让我的 Mcp3008 采样统一? - Is there any way to make my Mcp3008 sampling uniform? 如何使用mcp3008中的数据显示和动态更新多个wxpython静态文本? - how to display and dynamically update multiple wxpython static text with data from a mcp3008? 如何更改将mcp3008读取并显示降雨传感器数据的wxpython程序更改为软件spi? - How to change my wxpython program that read and display rain sensor data from mcp3008 to software spi? 如何以高频读取和累积传感器值,而无需不断写入磁盘(RPi 2 b+、MCP3304、Python) - How to read & accumulate sensor values at high frequency, without constantly writing to disk (RPi 2 b+, MCP3304, Python) RPi上的Python函数中的变量 - Variables in Python functions on RPi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM