7 Commits

Author SHA1 Message Date
Jordan-Fielding
3a961af1f8 Update main.py 2022-07-15 10:51:09 +10:00
Jordan-Fielding
529379ee3b Merge pull request #4 from Jordan-Fielding/Development
Update main.py
2022-07-11 10:52:17 +10:00
Jordan-Fielding
369a64ea98 Update main.py 2022-07-11 10:49:10 +10:00
Jordan-Fielding
a2152a6cf0 Update main.py 2022-07-08 14:00:05 +10:00
Jordan-Fielding
b329d8a3f9 Update main.py 2022-07-08 13:59:48 +10:00
Jordan-Fielding
a6d4a5ae87 Merge pull request #3 from Jordan-Fielding/Development
Update main.py
2022-07-08 13:58:31 +10:00
Jordan-Fielding
5921a64b8f Update main.py 2022-07-07 15:36:48 +10:00

36
main.py
View File

@@ -1,16 +1,17 @@
import RPi.GPIO as GPIO #Used to Import the LED import RPi.GPIO as GPIO #Used to Import the LED
import time #Used to allow wait times import time #Used to allow wait times
from picamera import PiCamera #Used to import the Camera from picamera import PiCamera #Used to import the Camera
from gpiozero import MotionSensor #Used to import the MotionSensor
from datetime import datetime from datetime import datetime
from subprocess import call
import os import os
pir = MotionSensor(4)
camera = PiCamera() #Camera Initialization camera = PiCamera() #Camera Initialization
GPIO.setwarnings(False) GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM) #Setting the GPIO Mode GPIO.setmode(GPIO.BCM) #Setting the GPIO Mode
GPIO.setup(22, GPIO.OUT) #LED output pin GPIO.setup(22, GPIO.OUT) #LED Flash Output
GPIO.setup(27, GPIO.OUT) #LED indicator output
cwd = os.getcwd() #Sets the Current Working Directory cwd = os.getcwd() #Sets the Current Working Directory
@@ -21,16 +22,19 @@ def bugmotion():
GPIO.output(22, 0) #Sets light off GPIO.output(22, 0) #Sets light off
print("\nProgram Running!") print("\nProgram Running!")
for i in range(3):
time.sleep(1)
GPIO.output(27, 1)
time.sleep(1)
GPIO.output(27, 0)
if i == 3:
break
#To stabilize sensor and Camera
#To stabilize the Camera
time.sleep(2) time.sleep(2)
while True: while True:
#Waits for Motion from PIR Sensor
pir.wait_for_motion()
print("\nBug detected")
#Turns on the LED Flash #Turns on the LED Flash
GPIO.output(22, 1) GPIO.output(22, 1)
@@ -38,7 +42,7 @@ def bugmotion():
# Grab the current time # Grab the current time
filePath = cwd + "/Pictures/" filePath = cwd + "/Pictures/"
currentTime = datetime.now() currentTime = datetime.now()
picTime = currentTime.strftime("%Y.%m.%d-%H%M") picTime = currentTime.strftime("%Y-%m-%d-%H-%M-%S")
picName = "Capture-" + picTime + '.jpg' picName = "Capture-" + picTime + '.jpg'
completeFilePath = filePath + picName completeFilePath = filePath + picName
#file_name = cwd + "/Pictures/Capture_" + str(time.time()) + ".jpg" #file_name = cwd + "/Pictures/Capture_" + str(time.time()) + ".jpg"
@@ -51,19 +55,15 @@ def bugmotion():
#Saves File #Saves File
camera.capture(completeFilePath) camera.capture(completeFilePath)
#Sets PIR Sensor back to waiting for motion
print("\nWaiting for no Motion!")
pir.wait_for_no_motion()
#Used to turn off the LED after 0.2 Secs #Used to turn off the LED after 0.2 Secs
time.sleep(0.2) time.sleep(0.2)
#Used to turn off the LED #Used to turn off the LED
GPIO.output(22, 0) GPIO.output(22, 0)
#Used to stabilize Sensor and allow the Camera to refocus #Used to wait 5 minutes for camera to take a photo
time.sleep(2) time.sleep(300)
print("\nSystem Ready!") print("\nTaking photo!")
def exit_handler(): def exit_handler():
print('Program Shutting Down!') print('Program Shutting Down!')