Advertisement
Guest User

ask_the_fish.py

a guest
Dec 12th, 2014
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. #!/usr/bin/python
  2. # Ask the fish
  3. # push the button and let the PiFish take the important decisions
  4. # Green=Yes Yellow=Maybe/Try Again Red=No
  5.  
  6. import RPi.GPIO as GPIO
  7. import time
  8. import random
  9.  
  10. LEDGPIOPin_Gruen = 4
  11. LEDGPIOPin_Rot = 9
  12. LEDGPIOPin_Gelb = 22
  13. LEDGPIOPin_BUZZ = 8
  14. LEDGPIOPin_BUTTON = 7
  15.  
  16. GPIO.setmode(GPIO.BCM)
  17. GPIO.setwarnings(False)
  18.  
  19. GPIO.setup(LEDGPIOPin_Gruen, GPIO.OUT)
  20. GPIO.setup(LEDGPIOPin_Gelb, GPIO.OUT)
  21. GPIO.setup(LEDGPIOPin_Rot, GPIO.OUT)
  22.  
  23. GPIO.setup(LEDGPIOPin_BUZZ, GPIO.OUT)
  24.  
  25. GPIO.setup(LEDGPIOPin_BUTTON, GPIO.IN)
  26.  
  27. GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
  28. GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
  29. GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
  30.  
  31. DELAYON = 0.01
  32. DELAYOFF = 0.01
  33. DELAYBUZZ = 0.05
  34. RESULT = 20
  35. i = 0
  36.  
  37. while True:
  38.         if (GPIO.input(LEDGPIOPin_BUTTON) == True):
  39.                 i = 0
  40.                 DELAYON = 0.01
  41.                 while (i < 100):
  42.                         RANDOM = random.randint(1, 3)
  43.                         DELAYON = DELAYON + 0.01
  44.                         print DELAYON
  45.                         print RANDOM
  46.                         GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
  47.                         GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
  48.                         GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
  49.                         time.sleep(DELAYOFF)
  50.                         if RANDOM == 1:
  51.                                 GPIO.output(LEDGPIOPin_Rot, GPIO.HIGH)
  52.                                 GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
  53.                                 GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
  54.                         elif RANDOM == 2:
  55.                                 GPIO.output(LEDGPIOPin_Gruen, GPIO.HIGH)
  56.                                 GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
  57.                                 GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
  58.                         else:
  59.                                 GPIO.output(LEDGPIOPin_Gelb, GPIO.HIGH)
  60.                                 GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
  61.                                 GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
  62.                         time.sleep(DELAYON)
  63.                         GPIO.output(LEDGPIOPin_BUZZ, GPIO.HIGH)
  64.                         time.sleep(DELAYBUZZ)
  65.                         GPIO.output(LEDGPIOPin_BUZZ, GPIO.LOW)
  66.  
  67.                         i += 2
  68.                 time.sleep(RESULT)
  69.                 GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
  70.                 GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
  71.                 GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
  72.                 GPIO.output(LEDGPIOPin_BUZZ, GPIO.LOW)
  73.                 i = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement