我想用10个孔的圆形阵列和接近传感器来计算旋转圆盘(上面有铝箔)的转速。你知道吗
不幸的是,我没有只计算事件(从铝箔到孔的变化),而是有很多不需要的数字。你知道吗
我试图弄清楚发生了什么事,但没有任何积极的结果。例如,如果我将铝箔固定在接近开关的对面(磁盘没有任何可见的运动),则每隔0.003-0.004秒就会不断调用detect_motion()函数。反弹时间不起作用。你知道吗
from __future__ import division
import RPi.GPIO as GPIO
import time
import Adafruit_PCA9685
import xlsxwriter
workbook = xlsxwriter.Workbook('Test.xlsx')
worksheet = workbook.add_worksheet()
pwm = Adafruit_PCA9685.PCA9685()
GPIO.setmode(GPIO.BCM)
pwm.set_pwm_freq(60)
pwm.set_pwm(0, 0, 4095)
pwm.set_pwm(1, 0, 1000)
time_motion = [0]
delta_time = [0]
row = 0
def detect_motion(ev=None):
global row
row += 1
time_motion.append(time.time())
a = time_motion[-1] - time_motion[-2]
print(a)
worksheet.write(row, 0, a)
workbook.close()
delta_time.append(a)
del time_motion[-2]
del delta_time[-2]
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(17, GPIO.FALLING, callback=detect_motion, bouncetime=10)
需要更改事件(箔到孔)之间的时间间隔。使用它们我将能够计算磁盘的转速。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐