Hey, super new to python and after following a few different tutorials and making a complete mess I was able to create a file to capture an image from my raspberry pi. however I cant figure out why or how to have the file always waiting for a button press. It works the first time then I assume stops. No errors.
Program was created in Thonny and F5 to run it. (not sure if its intended to only run once?) idk how else to start the script.
what I wanted to achieve was have it run and wait for a button press then take a picture and save it, which is does currently, however when I press the button a second time nothing happens.
This is my super messy code.
Program was created in Thonny and F5 to run it. (not sure if its intended to only run once?) idk how else to start the script.
what I wanted to achieve was have it run and wait for a button press then take a picture and save it, which is does currently, however when I press the button a second time nothing happens.
This is my super messy code.
import picamera from time import sleep from subprocess import call from gpiozero import Button from datetime import datetime button = Button(17) #filepath filePath = "/home/pi/Desktop/mmPictures/images/" #setting up date and time #grab the current time currentTime = datetime.now() #create filename for our picture picTime = currentTime.strftime("%Y.%m.%d-%H%m%S") picName = picTime + '.jpg' completeFilePath = filePath + picName button.wait_for_press() #setup the camera such that it closes when we are done with it print("Setting up") sleep(1) commandStop = "sudo systemctl stop motioneye" call ([commandStop], shell=True) print("Motioneye stopped") sleep(1) with picamera.PiCamera() as camera: camera.resolution = (1280, 720) #camera.capture("/home/pi/Desktop/mmPictures/images/newimage.jpg") camera.capture(completeFilePath) print("Picture taken") sleep(1) commandStart = "sudo systemctl start motioneye" call([commandStart], shell=True) print("Motioneye started")