rpi_assignments/Assignment 1/assignment_1.py

37 lines
712 B
Python

import RPi.GPIO as GPIO
import time
PIR_pin = 3
LED_pin = 4
GPIO.setmode(GPIO.BOARD)
GPIO.setup(LED_pin ,GPIO.OUT) # Set up pin to emit LED
GPIO.setwarnings(False)
GPIO.setup(PIR_pin, pull_up_down = GPIO.PUD_UP) # Set up pin 23 pull up
'''
def PIN_pin_ISR(pressed):
print("Falling Edge Detected")
'''
def Blink_3_times(pressed):
i = 0
while(i<=2):
GPIO.output(LED_pin, GPIO_HIGH)
time.sleep(1)
GPIO.output(LED_pin, GPIO_LOW)
time.sleep(1)
print("LED Blink")
GPIO.add_event_detect(PIR_PIN, GPIO.FALLING, callback = Blink_3_times, bouncetime = 300)
try:
while(1):
print("Nothing")
time.sleep(1)
except:
GPIO.cleanup()