I have a 3d printer with octoprint and i want to improve its control.
I want a way to turn on and off the printer by pushing a button next to the printer or using the telegram bot when I'm far from the printer.
I came from C++ and Arduino so i'm not very familiar with python and raspberry.
I created a script Toggle_Relay.py that reverse the state of a pin to turn on and off the printer and it works. Now i want to add the push button but I have some problem to develop the script because it works only one time I push the button, then the file "Toggle_Relay.py" is already imported and I can't reuse it. Do you have any suggestions? Maybe this is not the best forum where ask something like this but who knows
These are the scripts:
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(17,GPIO.OUT) GPIO.output(17, not(GPIO.input(17))) time.sleep(1)
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(27,GPIO.IN,pull_up_down=GPIO.PUD_UP) while True: buttonState = GPIO.input(27) if buttonState == False: #false = pressed import Toggle_Relay print("pressed") time.sleep(1)