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="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="PyDocumentationSettings">
|
||||||
|
<option name="renderExternalDocumentation" value="true" />
|
||||||
|
</component>
|
||||||
</module>
|
</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 RPi.GPIO as GPIO #Used to Import the LED
|
||||||
import time
|
import time #Used to allow wait times
|
||||||
from picamera import PiCamera
|
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.setwarnings(False)
|
||||||
GPIO.setmode(GPIO.BOARD)
|
GPIO.setmode(GPIO.BCM) #Setting the GPIO Mode
|
||||||
GPIO.setup(11, GPIO.IN) #Read output from PIR motion sensor
|
GPIO.setup(22, GPIO.OUT) #LED output pin
|
||||||
GPIO.setup(13, 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:
|
while True:
|
||||||
#ts = time.time()
|
|
||||||
#st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d_%H:%M:%S')
|
pir.wait_for_motion()
|
||||||
if i==0: #When output from motion sensor is LOW
|
print("Bug detected")
|
||||||
print ("No bugs detected",i)
|
GPIO.output(22, 1)
|
||||||
GPIO.output(13, 0) #Turn OFF LED
|
file_name = "/home/qldcomp/Pictures/img_" + str(time.time()) + ".jpg"
|
||||||
time.sleep(2)
|
camera.capture_sequence(file_name)
|
||||||
if i==1: #When output from motion sensor is HIGH
|
pir.wait_for_no_motion()
|
||||||
print("bugs detected",i)
|
time.sleep(1)
|
||||||
GPIO.output(13, 1) #Turn ON LED
|
GPIO.output(22, 0)
|
||||||
camera.capture('/home/pi/Pictures/img.jpg')
|
print("Bug Not Detected")
|
||||||
print("Photo Saved")
|
|
||||||
#os.system('libcamera-jpeg -o /home/pi/Pictures/image_Time_{}.jpg'.format(st))
|
|
||||||
camera.close() #Capture an Image
|
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user