Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Ask the fish
- # push the button and let the PiFish take the important decisions
- # Green=Yes Yellow=Maybe/Try Again Red=No
- import RPi.GPIO as GPIO
- import time
- import random
- LEDGPIOPin_Gruen = 4
- LEDGPIOPin_Rot = 9
- LEDGPIOPin_Gelb = 22
- LEDGPIOPin_BUZZ = 8
- LEDGPIOPin_BUTTON = 7
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- GPIO.setup(LEDGPIOPin_Gruen, GPIO.OUT)
- GPIO.setup(LEDGPIOPin_Gelb, GPIO.OUT)
- GPIO.setup(LEDGPIOPin_Rot, GPIO.OUT)
- GPIO.setup(LEDGPIOPin_BUZZ, GPIO.OUT)
- GPIO.setup(LEDGPIOPin_BUTTON, GPIO.IN)
- GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
- GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
- GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
- DELAYON = 0.01
- DELAYOFF = 0.01
- DELAYBUZZ = 0.05
- RESULT = 20
- i = 0
- while True:
- if (GPIO.input(LEDGPIOPin_BUTTON) == True):
- i = 0
- DELAYON = 0.01
- while (i < 100):
- RANDOM = random.randint(1, 3)
- DELAYON = DELAYON + 0.01
- print DELAYON
- print RANDOM
- GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
- GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
- GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
- time.sleep(DELAYOFF)
- if RANDOM == 1:
- GPIO.output(LEDGPIOPin_Rot, GPIO.HIGH)
- GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
- GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
- elif RANDOM == 2:
- GPIO.output(LEDGPIOPin_Gruen, GPIO.HIGH)
- GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
- GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
- else:
- GPIO.output(LEDGPIOPin_Gelb, GPIO.HIGH)
- GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
- GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
- time.sleep(DELAYON)
- GPIO.output(LEDGPIOPin_BUZZ, GPIO.HIGH)
- time.sleep(DELAYBUZZ)
- GPIO.output(LEDGPIOPin_BUZZ, GPIO.LOW)
- i += 2
- time.sleep(RESULT)
- GPIO.output(LEDGPIOPin_Rot, GPIO.LOW)
- GPIO.output(LEDGPIOPin_Gruen, GPIO.LOW)
- GPIO.output(LEDGPIOPin_Gelb, GPIO.LOW)
- GPIO.output(LEDGPIOPin_BUZZ, GPIO.LOW)
- i = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement