Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python的raspberry pi旋转编码器脚本_Python_Python 3.x_Raspberry Pi - Fatal编程技术网

使用python的raspberry pi旋转编码器脚本

使用python的raspberry pi旋转编码器脚本,python,python-3.x,raspberry-pi,Python,Python 3.x,Raspberry Pi,我有一个装置,其中我有一个电机,以每秒1转的速度转动直径为5厘米的轴。我需要在预定的转数后停止马达-现在假设是10转 我使用的传感器机构只是一个磁铁和簧片开关。下面的脚本可以很好地记录每次触发开关的情况 import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) button1=22 GPIO.setup(button1,GPIO.IN,pull_up_down=GPIO.PUD_UP) while(1): if GPIO.input(but

我有一个装置,其中我有一个电机,以每秒1转的速度转动直径为5厘米的轴。我需要在预定的转数后停止马达-现在假设是10转

我使用的传感器机构只是一个磁铁和簧片开关。下面的脚本可以很好地记录每次触发开关的情况

import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
button1=22
GPIO.setup(button1,GPIO.IN,pull_up_down=GPIO.PUD_UP)
while(1):
        if GPIO.input(button1)==0:
                print "Button 1 Pressed"
                sleep(0.5)
当此脚本运行电机时-

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BOARD)

Motor1A = 19
Motor1B = 21
Motor1E = 23

GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)

print "Going forwards"
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)

GPIO.cleanup()
简言之,我正在寻找的是一个组合脚本,它计算引脚22上的事件输入数,然后将引脚23(电机启用引脚)转到低电平,计数为10

非常感谢


尼克

所发布的只是一个节目描述。然而,我们需要你去。我们不能确定你想从我们这里得到什么。请在您的帖子中加入我们可以回答的有效问题。提醒:确保你知道;要求我们为您编写程序、建议和外部链接都是离题的。您有两个工作程序-是什么妨碍您使用变量存储循环计数并在循环内递增,直到达到10,然后关闭电机?问“请帮助我”的问题往往需要高度本地化的指导,或者在某些情况下,需要持续或私人的帮助,这不适合我们的问答形式。它也是相当模糊的,最好用一个更具体的问题来代替。请阅读,谢谢。注意到的要点。实际上,我刚刚发布了另一个问题,试图解决这个问题-[链接]