daily pastebin goal
20%
SHARE
TWEET

Eat The Orange

doidgy Jul 11th, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import time
  3. import random
  4. import RPi.GPIO as GPIO
  5.  
  6. GPIO.setmode(GPIO.BCM)
  7. GPIO.setwarnings(False)
  8.  
  9. LEDRed = 18
  10. LEDYellow = 23
  11. LEDGreen = 24
  12. ButtonPin = 25
  13.  
  14. GPIO.setup(LEDRed, GPIO.OUT)
  15. GPIO.setup(LEDYellow, GPIO.OUT)
  16. GPIO.setup(LEDGreen, GPIO.OUT)
  17. GPIO.setup(ButtonPin, GPIO.IN)
  18.  
  19. correct_button = 0
  20.  
  21. start = time.time()
  22.  
  23. while correct_button <= 10:
  24.     led_choice = random.randint(1,3)
  25.     if led_choice == 1:
  26.         led = LEDRed
  27.     if led_choice == 2:
  28.         led = LEDYellow
  29.         if GPIO.input(ButtonPin) == False:
  30.             correct_button = correct_button + 1
  31.     if led_choice == 3:
  32.         led = LEDGreen
  33.  
  34.     GPIO.output(led, GPIO.HIGH)
  35.     time.sleep(0.2)
  36.     GPIO.output(led, GPIO.LOW)
  37.  
  38. end = time.time()
  39.  
  40. time_taken = end - start
  41. time_taken = str(time_taken)
  42.  
  43. print("Time taken in seconds is " + time_taken)
  44.  
  45. GPIO.cleanup()
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