Skip to content

Instantly share code, notes, and snippets.

@uktechreviews
Created August 13, 2017 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uktechreviews/2e144546036b63d8ce47c3f72e51f527 to your computer and use it in GitHub Desktop.
Save uktechreviews/2e144546036b63d8ce47c3f72e51f527 to your computer and use it in GitHub Desktop.
from gpiozero import MotionSensor
from gpiozero import LED
from time import sleep
import random
green = LED(20)
red = LED(21)
sensor = MotionSensor(4)
while True:
print ("Starting again")
sleep(2)
red.on()
moved = False
wait = random.randint(0,5)
red.off()
green.on()
sleep(wait)
green.off()
red.on()
while moved==False:
if sensor.motion_detected:
print ("Spotted you move")
moved = True
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment