from RPLCD.i2c import CharLCD
import RPi.GPIO as GPIO
from time import sleep

button = 17
i = 2
# Create a dictionary of GPIO ports
lasers = {'2': 18,'4': 23,'6': 24,'8': 25}

preState = False
GPIO.setmode(GPIO.BCM)
GPIO.setup(button,GPIO.IN)
GPIO.setwarnings(False)
# Loop through the key and get the value to set to low and output
for x,v in lasers.items():
	GPIO.setup(v,GPIO.OUT)
	GPIO.output(v,GPIO.LOW)

lcd = CharLCD(i2c_expander='PCF8574', address=0x27, port=1, cols=16, rows=2, dotsize=8)
lcd.write_string('Pie Size Slicer')

while True:
	buttonValue = GPIO.input(button)
	if buttonValue == True:
		# Reset all lasers to off if back at 2
		if i == 2:
			for x,v in lasers.items():
				GPIO.output(v,GPIO.LOW)
		print (str(i) + " button is pressed")
		lcd.clear()
		lcd.write_string('Pie Size Slicer')
		# Allows you to write on the second line of the display
		lcd.crlf()
		lcd.write_string(str(i)+' : slices')
		# Use the key selected to get the value from the dictionary
		GPIO.output(lasers.get(str(i)),GPIO.HIGH)
		i = i+2
		if i > 8:
			i = 2
		preState = not preState
		while GPIO.input(button) == True:
			pass
		sleep(0.5)
