'''
Created on Dec 13, 2015

@author: Shannon Litwin
'''
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM
import Lib_LCD as LCD
import Lib_Main as BBB
import sys
import signal
import time

leftForward = "P8_46"
leftBackward = "P8_45"
rightForward = "P9_14"
rightBackward = "P9_16"

def Control_C_Exit(signal, frame):
    
    


signal.signal(signal.SIGINT, Control_C_Exit) # For cleaning up mid run

'''Keep to show Dr. Berry'''
LCD.init()

time.sleep(1)

LCD.backlight("on")

time.sleep(2)

LCD.backlight("off")

time.sleep(1)

line_message = "Hi Dr. Berry."
LCD.write_line(line_message)

time.sleep(5)

LCD.cursor_home()
long_message = "This is 35 chars and needs 2 lines."
LCD.write_screen(long_message)

time.sleep(5)

LCD.cursor_home()
long_message = "Which is fine because the screen can hold up to 80 characters."
LCD.write_screen(long_message)

time.sleep(5)

LCD.cursor_home()
long_message = "However, if the message is too long it will truncate. That is why you cannot read this entire message."
LCD.write_screen(long_message)

time.sleep(5)

LCD.clear()

m1 = "It works 1"
m2 = "It works 2"
m3 = "It works 3"
m4 = "It works 4"


time.sleep(1)

LCD.goto_line(4)
LCD.write_line(m4)
time.sleep(1)

LCD.goto_line(3)
LCD.write_line(m3)
time.sleep(1)

LCD.goto_line(2)
LCD.write_line(m2)
time.sleep(1)

LCD.goto_line(1)
LCD.write_line(m1)

LCD.clear()

#pause with while loop example
#start = time.time()
#end = time.time()
#while((end - start) < 3):
#    end = time.time()

BBB.cleanup_all()








GPIO.cleanup()
    PWM.cleanup()
    print("\nProgram halted! Exiting program!")
    sys.exit()