Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import RPi.GPIO as GPIO
- import time
- import I2C_LCD_driver
- GPIO.setmode(GPIO.BCM)
- mylcd = I2C_LCD_driver.lcd()
- counterPin = 18
- startBtn = 15
- exitBtn = 14
- startThread = 20
- doneThread = 26
- exitThread = 16
- GPIO.setup(doneThread, GPIO.IN, pull_up_down = GPIO.PUD_UP)
- GPIO.setup(startBtn, GPIO.IN, pull_up_down = GPIO.PUD_UP)
- GPIO.setup(exitBtn, GPIO.IN, pull_up_down = GPIO.PUD_UP)
- GPIO.setup(counterPin, GPIO.IN, pull_up_down = GPIO.PUD_UP)
- GPIO.setup(startThread, GPIO.OUT)
- GPIO.setup(exitThread, GPIO.OUT)
- coins = 0
- creditss = 0
- ready = False
- test = True
- ingame = False
- mylcd.lcd_display_string("Insert $1.00", 1, 4)
- mylcd.lcd_display_string("for 1 credit", 2, 4)
- mylcd.lcd_display_string("and press start when", 3, 0)
- mylcd.lcd_display_string("you're ready!", 4, 3)
- def started():
- GPIO.output(startThread, 1)
- time.sleep(0.2)
- GPIO.output(startThread, 0)
- def exited():
- GPIO.output(exitThread, 1)
- GPIO.output(startThread, 1)
- time.sleep(0.2)
- GPIO.output(exitThread, 0)
- GPIO.output(startThread, 0)
- while True:
- start = GPIO.input(startBtn)
- input_state = GPIO.input(counterPin)
- exit = GPIO.input(exitBtn)
- if ingame == False:
- if input_state == False:
- mylcd.lcd_clear()
- coins += 1
- time.sleep(0.09)
- mylcd.lcd_display_string(str(coins) + " cents inserted", 2, 1)
- if coins == 100:
- coins -= 100
- creditss += 1
- mylcd.lcd_display_string("You have " + str(creditss) + " credits", 3, 1)
- if creditss >= 1:
- ready = True
- if ingame == True:
- if start == False:
- started()
- if exit == False:
- mylcd.lcd_display_string(str(coins) + " cents inserted", 2, 1)
- if ingame == True:
- exited()
- ingame = False
- while ready == True:
- start = GPIO.input(startBtn)
- input_state = GPIO.input(counterPin)
- done = GPIO.input(doneThread)
- if input_state == False:
- mylcd.lcd_clear()
- coins += 25
- time.sleep(0.09)
- mylcd.lcd_display_string(str(coins) + " cents inserted", 2, 1)
- if coins == 100:
- coins -= 100
- creditss += 1
- mylcd.lcd_display_string("You have " + str(creditss) + " credits", 3, 1)
- if start == False:
- if creditss > 0:
- started()
- creditss -= 1
- ready = False
- ingame = True
- mylcd.lcd_clear()
- mylcd.lcd_display_string("Have Fun!", 2, 6)
- mylcd.lcd_display_string("You have " + str(creditss) + " credits", 3, 1)
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement