0

我正在尝试使用 python 代码控制步进电机。我知道这可能不是最好的方法,但请帮助我并忍受我。不久前我得到了这个工作,我很确定,我不知道为什么这不起作用。请帮助这是我下面的代码

def motor_run_till_press(btnPin, clockwise):
    import gpiozero
    
    button = gpiozero.Button(btnPin) #declares the limir switch

    def motor_on(clockwise):
        import os
        os.system("cd /home/pi/printer/A4988CustomFeatures && python3 motor_file_for_kill.py")

    from threading import Thread
    motor_thread = Thread(target=motor_on, args=[clockwise])

    motor_thread.start()
    
    pressed = button.is_pressed()    
    while True:
        if pressed:
            import sys
            sys.path.append('/home/pi/printer/A4988CustomFeatures')
            import kill_motor as killMotor
            try:
                motor_thread.join()
            finally:
                return(True)
        else:
            pass
    ```


This is the error i get

Traceback (most recent call last):
  File "/home/pi/printer/Debug/main.py", line 14, in <module>
    motor.motor_run_till_press(17, True)
  File "/home/pi/printer/A4988CustomFeatures/BTN_control.py", line 15, in motor_run_till_press
    pressed = button.is_pressed()    
TypeError: 'bool' object is not callable

4

2 回答 2

1

.is_pressed()指向在您的情况下不存在的函数调用。

.is_pressed指向按钮是否被按下的布尔值。

删除括号 ()。

button.is_pressed()-->button.is_pressed

于 2022-01-30T17:55:41.243 回答
0

更改button.is_pressed()button.is_pressed

于 2022-01-30T17:53:04.997 回答