From 11308d1f107760e409d022735615ea2eb1812f03 Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 12 Oct 2023 11:32:41 +0700 Subject: [PATCH] rename dir --- Assignment 1/assignment_1.py | 43 ----------------------------------- assignment_1/assignment_1.py | 44 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 assignment_1/assignment_1.py 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