Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import RPi.GPIO as GPIO
  4. import time
  5. import subprocess, os
  6. import signal
  7. GPIO.setmode(GPIO.BCM)
  8. GPIO.setwarnings(False)
  9. RearView_Switch = 24 # Your GPIO pin here
  10. GPIO.setup(RearView_Switch,GPIO.IN, pull_up_down=GPIO.PUD_UP)
  11.  
  12. try:
  13.  
  14. run = 0
  15. while True :
  16. time.sleep(0.1)
  17. if GPIO.input(RearView_Switch)==0 and run == 0:
  18. rpistr = "raspivid -t 0 -vf -w 1280 -h 720 -fps 30" # Tweak for your camera setup.
  19. p=subprocess.Popen(rpistr,shell=True, preexec_fn=os.setsid)
  20. run = 1
  21. while GPIO.input(RearView_Switch)==0:
  22. time.sleep(0.1)
  23. if GPIO.input(RearView_Switch)==1 and run == 1:
  24. run = 0
  25. os.killpg(p.pid, signal.SIGTERM)
  26. while GPIO.input(RearView_Switch)==1:
  27. time.sleep(0.1)
  28.  
  29. except KeyboardInterrupt:
  30. GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement