93 lines
2.4 KiB
Python
93 lines
2.4 KiB
Python
import RPi.GPIO as GPIO
|
|
from uldaq import (get_daq_device_inventory, DaqDevice, AInScanFlag, ScanStatus,
|
|
ScanOption, create_float_buffer, InterfaceType, AiInputMode)
|
|
from time import time, sleep
|
|
|
|
|
|
def GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin):
|
|
# LED output pins
|
|
GPIO.setmode(GPIO.BOARD)
|
|
|
|
GPIO.setup(LED1_pin, GPIO.OUT) # 1
|
|
GPIO.output(LED1_pin, GPIO.LOW)
|
|
GPIO.setup(LED2_pin, GPIO.OUT) # 2
|
|
GPIO.output(LED2_pin, GPIO.LOW)
|
|
|
|
LED_status = [False, False]
|
|
|
|
# switch controlled input
|
|
GPIO.setup(Button1_pin, GPIO.IN)
|
|
GPIO.setup(Button2_pin, GPIO.IN)
|
|
|
|
# GPIO.setup(Button1_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
|
# GPIO.setup(Button2_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
|
|
|
return LED_status
|
|
|
|
|
|
def main():
|
|
LED1_pin = 11
|
|
LED2_pin = 13
|
|
Button1_pin = 16
|
|
Button2_pin = 18
|
|
|
|
LED_status = GPIO_setup(LED1_pin, LED2_pin, Button1_pin, Button2_pin)
|
|
|
|
LED1_t = time()
|
|
LED1_t_interval = 2
|
|
|
|
LED2_t = time()
|
|
LED2_t_interval = 1
|
|
|
|
t0 = time()
|
|
|
|
# loop_t = time()
|
|
|
|
while time() - t0 < 30:
|
|
# print(time() - loop_t)
|
|
# LED1 blink every 2 sec
|
|
if time() - LED1_t < .1 and LED_status[0] == False:
|
|
LED_status[0] = True
|
|
GPIO.output(LED1_pin, GPIO.HIGH)
|
|
if time() - LED1_t >= .1 and LED_status[0] == True:
|
|
LED_status[0] = False
|
|
GPIO.output(LED1_pin, GPIO.LOW)
|
|
|
|
if time() - LED1_t >= LED1_t_interval:
|
|
LED1_t = time()
|
|
|
|
|
|
# LED blink every 1 sec
|
|
if time() - LED2_t < .1 and LED_status[1] == False:
|
|
LED_status[1] = True
|
|
GPIO.output(LED2_pin, GPIO.HIGH)
|
|
if time() - LED2_t >= .1 and LED_status[1] == True:
|
|
LED_status[1] = False
|
|
GPIO.output(LED2_pin, GPIO.LOW)
|
|
|
|
if time() - LED2_t >= LED2_t_interval:
|
|
LED2_t = time()
|
|
|
|
|
|
# button press check !!!
|
|
if GPIO.input(Button1_pin) == GPIO.HIGH:
|
|
print('button 1 pressed')
|
|
|
|
if GPIO.input(Button2_pin) == GPIO.HIGH:
|
|
print('button 2 pressed')
|
|
if GPIO.input(Button1_pin) == GPIO.HIGH:
|
|
if LED_status[0] == False:
|
|
GPIO.output(LED1_pin, GPIO.HIGH)
|
|
if LED_status[1] == False:
|
|
GPIO.output(LED2_pin, GPIO.HIGH)
|
|
sleep(2)
|
|
break
|
|
|
|
# loop_t = time()
|
|
|
|
|
|
GPIO.cleanup()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|