0

I'm trying to control a stepper motor with python code. I know this may not be the best way but please just help me and bear with me. I got this working a while ago I'm pretty sure and I have no idea why this isn't working. Please help this is my code below

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

2 Answers2

1

.is_pressed() points to a function call which in your case doesn't exist.

.is_pressed points to a bool value of whether the button is pressed or not.

Remove the brackets ().

button.is_pressed() --> button.is_pressed

ahmadjanan
  • 298
  • 2
  • 9
0

Change button.is_pressed() to button.is_pressed

Bob
  • 1