SHARE
TWEET

Untitled

a guest May 26th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###import Python Modules ###
  2. import threading
  3. import RPi.GPIO as GPIO #import GPIO functionality
  4. import time
  5. from time import sleep
  6.  
  7. ### Set GPIO pins and all setups needed ###
  8. GPIO.setmode(GPIO.BCM) #Numbers GPIOs ny physical location
  9. GPIO.setwarnings(False) #
  10.  
  11. GREEN_BUTTON = 25
  12. RED_BUTTON = 18
  13. YELLOW_BUTTON = 27
  14. BLUE_BUTTON = 22
  15.  
  16. GREEN_LED = 5
  17. RED_LED = 6
  18. YELLOW_LED = 12
  19. BLUE_LED = 13
  20.  
  21. START_BUTTON = 0
  22. interrupt = 0
  23.  
  24. GPIO.setup(GREEN_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #GPIO 25: GREEN BUTTON
  25. GPIO.setup(RED_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #GPIO 18: RED BUTTON
  26. GPIO.setup(YELLOW_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #GPIO 27: YELLOW BUTTON
  27. GPIO.setup(BLUE_BUTTON, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) #GPIO 22: BLUE BUTTON
  28.  
  29.  
  30. GPIO.setup(GREEN_LED, GPIO.OUT) #GREEN OUT
  31. GPIO.setup(RED_LED, GPIO.OUT) #RED OUT  
  32. GPIO.setup(YELLOW_LED, GPIO.OUT) #YELLOW OUT
  33. GPIO.setup(BLUE_LED, GPIO.OUT) #BLUE OUT
  34.  
  35. ##GPIO.output(GREEN_LED, GPIO.LOW)
  36. ##GPIO.output(RED_LED, GPIO.LOW)
  37. ##GPIO.output(YELLOW_LED, GPIO.LOW)
  38. ##GPIO.output(BLUE_LED, GPIO.LOW)
  39.  
  40. def yellow_pressed(yellow, blue):
  41.     print("YELLOW PRESSED")
  42.     GPIO.output(YELLOW_LED, GPIO.HIGH)
  43.     global START_BUTTON
  44.     START_BUTTON = yellow
  45.     global interrupt
  46.     interrupt = blue
  47.  
  48. def blue_pressed(blue, yellow):
  49.     print("BLUE PRESSED")
  50.     GPIO.output(BLUE_LED, GPIO.HIGH)
  51.     global START_BUTTON
  52.     START_BUTTON = blue
  53.     global interrupt
  54.     interrupt = yellow
  55.  
  56. def checker(pin):
  57.     if pin == YELLOW_BUTTON or pin == BLUE_BUTTON:
  58.         if GPIO.input(GREEN_BUTTON) and GPIO.input(RED_BUTTON):
  59.             blink()
  60.  
  61. def blink():
  62.     for i in range(10):
  63.         print('LED ON')
  64.         GPIO.output(GREEN_LED, GPIO.HIGH)
  65.         GPIO.output(RED_LED, GPIO.HIGH)
  66.         time.sleep(1)
  67.         print('LED OFF')
  68.         GPIO.output(GREEN_LED, GPIO.LOW)
  69.         GPIO.output(RED_LED, GPIO.LOW)
  70.         time.sleep(1)
  71.         if GPIO.input(interrupt):
  72.             break
  73.     GPIO.output(GREEN_LED, GPIO.LOW)
  74.     GPIO.output(RED_LED, GPIO.LOW)
  75.     GPIO.output(BLUE_LED, GPIO.LOW)
  76.     GPIO.output(YELLOW_LED, GPIO.LOW)
  77.        
  78.        
  79.  
  80. if __name__ == "__main__":
  81.     #setup()
  82. ##    GPIO.output(GREEN_LED, GPIO.LOW)
  83. ##    GPIO.output(RED_LED, GPIO.LOW)
  84. ##    GPIO.output(BLUE_LED, GPIO.LOW)
  85. ##    GPIO.output(YELLOW_LED, GPIO.LOW)
  86.     GPIO.add_event_detect(GREEN_BUTTON, GPIO.RISING, callback = lambda x: checker(START_BUTTON), bouncetime = 222)
  87.     GPIO.add_event_detect(RED_BUTTON, GPIO.RISING, callback = lambda x: checker(START_BUTTON), bouncetime = 222)
  88.     GPIO.add_event_detect(YELLOW_BUTTON, GPIO.RISING, callback = lambda x: yellow_pressed(YELLOW_BUTTON, BLUE_BUTTON), bouncetime = 222)
  89.     GPIO.add_event_detect(BLUE_BUTTON, GPIO.RISING, callback = lambda x: blue_pressed(BLUE_BUTTON, YELLOW_BUTTON), bouncetime = 222)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top