diff --git a/Assignment 1/assignment_1.py b/Assignment 1/assignment_1.py index ae6798a..365b261 100755 --- a/Assignment 1/assignment_1.py +++ b/Assignment 1/assignment_1.py @@ -1,44 +1 @@ -#! /usr/bin/python -import RPi.GPIO as GPIO -import time - -global blinking, blink_count - -blinking: bool = False -led_state: bool = False -blink_count: int = 0 - -LED_PIN = 2 -BTN_PIN = 3 - -GPIO.setmode(GPIO.BCM) -GPIO.setwarnings(False) -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): - global blinking, blink_count - time.sleep(0.05) - blinking = not GPIO.input(BTN_PIN) - if(blinking): - blink_count = 0 - -GPIO.add_event_detect(BTN_PIN, GPIO.BOTH, callback = ISR_DECT_BOTH, bouncetime = 50) - -try: - while(1): - 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) -except: - GPIO.cleanup() - \ No newline at end of file diff --git a/assignment_1/assignment_1.py b/assignment_1/assignment_1.py new file mode 100644 index 0000000..ae6798a --- /dev/null +++ b/assignment_1/assignment_1.py @@ -0,0 +1,44 @@ +#! /usr/bin/python +import RPi.GPIO as GPIO +import time + +global blinking, blink_count + +blinking: bool = False +led_state: bool = False +blink_count: int = 0 + +LED_PIN = 2 +BTN_PIN = 3 + +GPIO.setmode(GPIO.BCM) +GPIO.setwarnings(False) +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): + global blinking, blink_count + time.sleep(0.05) + blinking = not GPIO.input(BTN_PIN) + if(blinking): + blink_count = 0 + +GPIO.add_event_detect(BTN_PIN, GPIO.BOTH, callback = ISR_DECT_BOTH, bouncetime = 50) + +try: + while(1): + 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) +except: + GPIO.cleanup() + \ No newline at end of file