import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(7,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)

segments=(24,12,19,21,23,22,15,11)

for segment in segments:
    GPIO.setup(segment,GPIO.OUT)
    GPIO.output(segment,GPIO.LOW)
digits=(26,18,16,13)

for digit in digits:
    GPIO.setup(digit,GPIO.OUT)
    GPIO.output(digit,GPIO.HIGH)
num = {'':(0,0,0,0,0,0,0),
'0':(1,1,1,1,1,1,0),
'1':(0,1,1,0,0,0,0),
'2':(1,1,0,1,1,0,1),
'3':(1,1,1,1,0,0,1),
'4':(0,1,1,0,0,1,1),
'5':(1,0,1,1,0,1,1),
'6':(1,0,1,1,1,1,1),
'7':(1,1,1,0,0,0,0),
'8':(1,1,1,1,1,1,1),
'9':(1,1,1,1,0,1,1)
}
try:
    while True:
        n = time.ctime()[11:13]+time.ctime()[14:16]
        s = str(n).rjust(4)
        for digit in range(4):
            for loop in range(0,7):
                GPIO.output(segments[loop],num[s[digit]][loop])
        if (int(time.ctime()[18:19])%2 == 0) and (digit == 1):
            GPIO.output(11,1)
        else:
            GPIO.output(11,0)
        GPIO.output(digits[digit],0)
        time.sleep(1)
        print(s)
        GPIO.output(digits[digit],1)
        time.sleep(1)
except KeyboardInterrupt:
    GPIO.cleanup()