daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Jul 12th, 2016 64 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.     GPIO.output(led, GPIO.HIGH)
  26.     button_seen = False
  27.     for i in range(200):
  28.         if led_choice == 1:
  29.             led = LEDRed
  30.         if led_choice == 2:
  31.             led = LEDYellow
  32.             if GPIO.input(ButtonPin) == False:
  33.                 button_seen = True
  34.         if led_choice == 3:
  35.             led = LEDGreen
  36.         time.sleep(0.001)
  37.     if button_seen:
  38.         correct_button = correct_button + 1
  39.     GPIO.output(led, GPIO.LOW)
  40.  
  41. end = time.time()
  42.  
  43. time_taken = end - start
  44. time_taken = str(time_taken)
  45.  
  46. print("Time taken in seconds is " + time_taken)
  47.  
  48. GPIO.cleanup()
RAW Paste Data
Top