Hi Folks
I have been working on a project which uses a PIR to detect movement turn on an LED, Take a photo and scroll a message whilst movement is detected.
All the elements function as expected except when movement is no longer detected. I would like the Scroll Phat to reset its self so nothing is displayed.
I would consider myself technical but not a programmer.
I have cobbled together, with some tweeks a python script but for the life of me I can’t get it to clear the Scroll Phat.
I would be grateful for any pearls of wisdom.
Thanks
Jon
Please see code below:
#PIR Sensor with LED, Camera and LED Scroll
import RPi.GPIO as GPIO
import signal
import time
import scrollphathd
from picamera import PiCamera
from time import sleep
GPIO.setmode(GPIO.BOARD) #Set GPIO to pin numbering
pir = 8 #Assign pin 8 to PIR
led = 10 #Assign pin 10 to LED
camera = PiCamera()
GPIO.setup(pir, GPIO.IN) #Setup GPIO pin PIR as input
GPIO.setup(led, GPIO.OUT) #Setup GPIO pin for LED as output
print (“Sensor initializing . . .”)
time.sleep(2) #Give sensor time to startup
print (“Active”)
print (“Press Ctrl+c to end program”)
try:
while True:
if GPIO.input(pir) == True: #If PIR pin goes high, motion is detected
print (“Motion Detected!”)
GPIO.output(led, True) #Turn on LED
scrollphathd.write_string(“POLICE POLITZI”, brightness=0.5,)
time.sleep(4) #Keep LED on for 4 seconds
camera.capture(’/home/pi/Desktop/image.jpg’)
GPIO.output(led, False) #Turn off LED
scrollphathd.show() # Scroll the buffer content
scrollphathd.scroll() # Wait for 0.1s
time.sleep(0.1)
except KeyboardInterrupt: #Ctrl+c
scrollphathd.clear()
#sys.exit(-1)
pass #Do nothing, continue to finally
finally:
GPIO.output(led, False) #Turn off LED in case left on
GPIO.cleanup() #reset all GPIO
print (“Program ended”)