#
#count down timer 
#
# by Brian Corteil aka on Twitter @CannonFodder
#
# free to use
#
import pygame
import sys
import os,time, datetime
from datetime import timedelta
import I2C_LCD_driver
#from time import *

pygame.mixer.init()
pygame.mixer.music.set_volume(1.0)
mylcd = I2C_LCD_driver.lcd()


# enter target time and date here
day= 20
month= 01
year= 2017
hour= 12
minutes= 00
sec= 0

days_old=99
hrs_old=99
mins_old=99
mylcd.lcd_clear()

targetTime = datetime.datetime(year, month, day, hour, minutes) # sets up target time
timeNow =datetime.datetime.now()

while timeNow <= targetTime:

    timeNow =datetime.datetime.now() # the time now
    remainingTime=(targetTime-timeNow)
    days = remainingTime.days
    secs = remainingTime.seconds
    hrs, secs = divmod(secs, 3600)
    mins, secs = divmod(secs, 60)
    
    sys.stdout.write("\r%dd %dh %dm %ds to Presidential Inauguration!    " % (days, hrs, mins, secs))
    sys.stdout.flush()
    # mylcd.lcd_clear()
    mylcd.lcd_display_string("Days Hrs Min Sec", 1)
    if days != days_old:  # only update LCD if days value changes
        mylcd.lcd_display_string("  ", 2,1)
        mylcd.lcd_display_string(str(days), 2,1)
        days_old = days
    if hrs != hrs_old:
        mylcd.lcd_display_string("  ", 2,5)
        mylcd.lcd_display_string(str(hrs), 2,5)
        hrs_old = hrs
    if mins != mins_old:
        mylcd.lcd_display_string("  ", 2,9)
        mylcd.lcd_display_string(str(mins), 2,9)
        mins_old = mins
    mylcd.lcd_display_string("  ", 2,13)
    mylcd.lcd_display_string(str(secs), 2,13)
    time.sleep(1)
    
# What happens when countdown ends    
mylcd.lcd_clear()

pygame.mixer.music.load("DRUMROLL.WAV")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
    continue
    
mylcd.lcd_display_string("Trump in Charge!", 1)

str_pad = " " * 16
my_long_string = "Make America Great Again"
my_long_string = str_pad + my_long_string

for i in range (0, len(my_long_string)):
 lcd_text = my_long_string[i:(i+16)]
 mylcd.lcd_display_string(lcd_text,2)
 time.sleep(0.4)
 mylcd.lcd_display_string(str_pad,2) 

pygame.mixer.music.load("remsong.mp3")
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
    continue
 
