daily pastebin goal
34%
SHARE
TWEET

Everything Script

a guest Mar 8th, 2018 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import RPi.GPIO as GPIO
  2. import time
  3. import I2C_LCD_driver
  4.  
  5. GPIO.setmode(GPIO.BCM)
  6. mylcd = I2C_LCD_driver.lcd()
  7. counterPin = 18
  8. startBtn = 15
  9. exitBtn = 14
  10. startThread = 20
  11. doneThread = 26
  12. exitThread = 16
  13. GPIO.setup(doneThread, GPIO.IN, pull_up_down = GPIO.PUD_UP)
  14. GPIO.setup(startBtn, GPIO.IN, pull_up_down = GPIO.PUD_UP)
  15. GPIO.setup(exitBtn, GPIO.IN, pull_up_down = GPIO.PUD_UP)
  16. GPIO.setup(counterPin, GPIO.IN, pull_up_down = GPIO.PUD_UP)
  17. GPIO.setup(startThread, GPIO.OUT)
  18. GPIO.setup(exitThread, GPIO.OUT)
  19. coins = 0
  20. creditss = 0
  21. ready = False
  22. test = True
  23. ingame = False
  24.  
  25. mylcd.lcd_display_string("Insert $1.00", 1, 4)
  26. mylcd.lcd_display_string("for 1 credit", 2, 4)
  27. mylcd.lcd_display_string("and press start when", 3, 0)
  28. mylcd.lcd_display_string("you're ready!", 4, 3)
  29.  
  30. def started():
  31.     GPIO.output(startThread, 1)
  32.     time.sleep(0.2)
  33.     GPIO.output(startThread, 0)
  34.    
  35. def exited():
  36.     GPIO.output(exitThread, 1)
  37.     GPIO.output(startThread, 1)
  38.     time.sleep(0.2)
  39.     GPIO.output(exitThread, 0)
  40.     GPIO.output(startThread, 0)
  41.  
  42. while True:
  43.     start = GPIO.input(startBtn)
  44.     input_state = GPIO.input(counterPin)
  45.     exit = GPIO.input(exitBtn)
  46.     if ingame == False:
  47.         if input_state == False:
  48.             mylcd.lcd_clear()
  49.             coins += 1
  50.             time.sleep(0.09)
  51.             mylcd.lcd_display_string(str(coins) + " cents inserted", 2, 1)
  52.         if coins == 100:
  53.             coins -= 100
  54.             creditss += 1
  55.             mylcd.lcd_display_string("You have " + str(creditss) + " credits", 3, 1)
  56.         if creditss >= 1:
  57.             ready = True
  58.     if ingame == True:
  59.         if start == False:
  60.             started()
  61.     if exit == False:
  62.         mylcd.lcd_display_string(str(coins) + " cents inserted", 2, 1)
  63.         if ingame == True:
  64.             exited()
  65.             ingame = False
  66.     while ready == True:
  67.         start = GPIO.input(startBtn)
  68.         input_state = GPIO.input(counterPin)
  69.         done = GPIO.input(doneThread)
  70.         if input_state == False:
  71.             mylcd.lcd_clear()
  72.             coins += 25
  73.             time.sleep(0.09)
  74.             mylcd.lcd_display_string(str(coins) + " cents inserted", 2, 1)
  75.         if coins == 100:
  76.             coins -= 100
  77.             creditss += 1
  78.             mylcd.lcd_display_string("You have " + str(creditss) + " credits", 3, 1)
  79.         if start == False:
  80.             if creditss > 0:
  81.                 started()
  82.                 creditss -= 1
  83.                 ready = False
  84.                 ingame = True
  85.                 mylcd.lcd_clear()
  86.                 mylcd.lcd_display_string("Have Fun!", 2, 6)
  87.                 mylcd.lcd_display_string("You have " + str(creditss) + " credits", 3, 1)
  88.                 break
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