Edit Assignment 1
This commit is contained in:
parent
138f84efb6
commit
95d6e2dfda
|
@ -1,37 +1,44 @@
|
||||||
|
#! /usr/bin/python
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
import time
|
import time
|
||||||
|
|
||||||
PIR_pin = 3
|
global blinking, blink_count
|
||||||
LED_pin = 4
|
|
||||||
|
|
||||||
GPIO.setmode(GPIO.BOARD)
|
blinking: bool = False
|
||||||
GPIO.setup(LED_pin ,GPIO.OUT) # Set up pin to emit LED
|
led_state: bool = False
|
||||||
|
blink_count: int = 0
|
||||||
|
|
||||||
|
LED_PIN = 2
|
||||||
|
BTN_PIN = 3
|
||||||
|
|
||||||
|
GPIO.setmode(GPIO.BCM)
|
||||||
GPIO.setwarnings(False)
|
GPIO.setwarnings(False)
|
||||||
GPIO.setup(PIR_pin, pull_up_down = GPIO.PUD_UP) # Set up pin 23 pull up
|
GPIO.setup(LED_PIN ,GPIO.OUT)
|
||||||
|
GPIO.setup(BTN_PIN,GPIO.IN, pull_up_down = GPIO.PUD_UP)
|
||||||
|
|
||||||
|
blinking = not GPIO.input(BTN_PIN)
|
||||||
|
|
||||||
'''
|
def ISR_DECT_BOTH(channel: int):
|
||||||
def PIN_pin_ISR(pressed):
|
global blinking, blink_count
|
||||||
print("Falling Edge Detected")
|
time.sleep(0.05)
|
||||||
'''
|
blinking = not GPIO.input(BTN_PIN)
|
||||||
|
if(blinking):
|
||||||
def Blink_3_times(pressed):
|
blink_count = 0
|
||||||
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)
|
|
||||||
|
|
||||||
|
GPIO.add_event_detect(BTN_PIN, GPIO.BOTH, callback = ISR_DECT_BOTH, bouncetime = 50)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while(1):
|
while(1):
|
||||||
print("Nothing")
|
print(blinking)
|
||||||
|
if(blinking):
|
||||||
|
if led_state == 0:
|
||||||
|
blink_count += 1
|
||||||
|
if blink_count <= 3:
|
||||||
|
led_state = not led_state
|
||||||
|
else:
|
||||||
|
led_state = False
|
||||||
|
GPIO.output(LED_PIN, led_state)
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
except:
|
except:
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
|
Loading…
Reference in New Issue