#!/usr/bin/python
# Project Maker
# Sean Taylor
# June 2016
# Example Program 2 (MOTION)
# Circuit Description:
# GPIO17<------(+)(RED LED)(-)--->[220Ohm]--->GND
# GPIO4 <------(Motion Sensor)---(+)-->5V, (-)--->GND
import sys
import RPi.GPIO as GPIO

ON  = 1
OFF = 0
LOOP = 1
motion = 0

GPIO.setmode(GPIO.BOARD)

GPIO17 = 11     # LED
GPIO4  = 7      # motion sensor

GPIO.setup(GPIO17, GPIO.OUT)
GPIO.setup(GPIO4, GPIO.IN)

GPIO.output(GPIO17, OFF)

while LOOP==1:
    motion = GPIO(GPIO4)
    if motion == 1:
        GPIO.output(GPIO17, ON)     # motion detected, LED ON
    else:
        GPIO.output(GPIO17, OFF)    # no motion detected, LED OFF
        
GPIO.cleanup()  # infinite loop so this will not be executed
