Python GPIO Changes
This commit is contained in:
3
.idea/BugMotion.iml
generated
3
.idea/BugMotion.iml
generated
@@ -8,4 +8,7 @@
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<component name="PyDocumentationSettings">
|
||||
<option name="renderExternalDocumentation" value="true" />
|
||||
</component>
|
||||
</module>
|
||||
7
.idea/other.xml
generated
Normal file
7
.idea/other.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="PySciProjectComponent">
|
||||
<option name="PY_SCI_VIEW" value="true" />
|
||||
<option name="PY_SCI_VIEW_SUGGESTED" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
45
main.py
45
main.py
@@ -1,31 +1,30 @@
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
from picamera import PiCamera
|
||||
import RPi.GPIO as GPIO #Used to Import the LED
|
||||
import time #Used to allow wait times
|
||||
from picamera import PiCamera #Used to import the Camera
|
||||
from gpiozero import MotionSensor #Used to import the MotionSensor
|
||||
|
||||
camera = PiCamera()
|
||||
pir = MotionSensor(4)
|
||||
camera = PiCamera() #Camera Initialization
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BOARD)
|
||||
GPIO.setup(11, GPIO.IN) #Read output from PIR motion sensor
|
||||
GPIO.setup(13, GPIO.OUT) #LED output pin
|
||||
GPIO.setmode(GPIO.BCM) #Setting the GPIO Mode
|
||||
GPIO.setup(22, GPIO.OUT) #LED output pin
|
||||
|
||||
i=GPIO.input(11)
|
||||
|
||||
time.sleep(2) # to stabilize sensor
|
||||
|
||||
time.sleep(2) # to stabilize sensor and Camera
|
||||
while True:
|
||||
#ts = time.time()
|
||||
#st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S')
|
||||
if i==0: #When output from motion sensor is LOW
|
||||
print ("No bugs detected",i)
|
||||
GPIO.output(13, 0) #Turn OFF LED
|
||||
time.sleep(2)
|
||||
if i==1: #When output from motion sensor is HIGH
|
||||
print("bugs detected",i)
|
||||
GPIO.output(13, 1) #Turn ON LED
|
||||
camera.capture('/home/pi/Pictures/img.jpg')
|
||||
print("Photo Saved")
|
||||
#os.system('libcamera-jpeg -o /home/pi/Pictures/image_Time_{}.jpg'.format(st))
|
||||
camera.close() #Capture an Image
|
||||
time.sleep(2)
|
||||
|
||||
pir.wait_for_motion()
|
||||
print("Bug detected")
|
||||
GPIO.output(22, 1)
|
||||
file_name = "/home/qldcomp/Pictures/img_" + str(time.time()) + ".jpg"
|
||||
camera.capture_sequence(file_name)
|
||||
pir.wait_for_no_motion()
|
||||
time.sleep(1)
|
||||
GPIO.output(22, 0)
|
||||
print("Bug Not Detected")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user