The FAB contributors over at Instructables have a nice how to on a camera trap.
www.instructables.com/Simple-Raspberry-Pi-Camera-Trap-Made-From-a-Food-C/
www.instructables.com/Simple-Raspberry-Pi-Camera-Trap-Made-From-a-Food-C/
#! /usr/bin/python
#import RPi.GPIO as GPIO
import time
from random import sample
def checkdist():
time.sleep(0.000015)
t1 = time.time()
time.sleep(2)
t2 = time.time()
return (t2-t1)*340/2
def fakedist():
list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
return sample(list1,1)[0]
time.sleep(1)
gled="off"
yled="off"
rled="off"
print(gled, yled, rled)
try:
while True:
print('Distance: %0.2f m' %checkdist())
dist = fakedist()
print('fake: %0.2f m' %dist)
if dist > 7:
gled="on"
yled="off"
rled="off"
if dist > 2 and dist < 8:
gled="off"
yled="on"
rled="off"
if dist < 3:
gled="off"
yled="off"
rled="on"
print(gled, yled, rled)
time.sleep(0.5)
except KeyboardInterrupt:
pass
Let me count thy ways. There are many.
Here is one: CodeShare
Share your code and you get a link similar to https://codeshare.io/Od7Q8g that you can share with others. It dissolves after 24 hours, you get create an account for more persistent storage.