#! /usr/bin/env python

import ZeroSeg.led as led
import time
from datetime import datetime

def clock(device, deviceId, seconds):
	for _ in xrange(seconds):
		now = datetime.now()
		hour = now.hour
		minute = now.minute
		second = now.second
		dot = second % 2 == 0
		# Set hours
		device.letter(deviceId, 4, int(hour/10)) # Tens
		device.letter(deviceId, 3, hour % 10, dot) # Ones
		# Set minutes
		device.letter(deviceId, 2, int(minute / 10)) # Tens
		device.letter(deviceId, 1, minute % 10) # Ones
		time.sleep(1)
		
device = led.sevensegment(cascaded = 2)

while True: 
	clock(device, 1, seconds = 10)
