Clock update

On October 25, 2015, in General, by Neil Stevens
So I decided to be lazy and just have my clock’s interface be a computer program:
import datetime
import glob
import serial
import sys
import time

if len(sys.argv) > 1:
	port = sys.argv[1]
else:
	port = glob.glob('/dev/tty.usbmodem*')[0]

print "Writing to %s" % port

arduino = serial.Serial(port, 9600)
time.sleep(3)
arduino.write("SEIZE\n")

result = arduino.readline().strip()
if not result == "YOU":
	print("Clock not found\n")
	sys.exit(1)

print("Clock found, setting to current time.")

arduino.write("SET\n");
print(arduino.readline().strip());

arduino.write("%s\n" % time.strftime('%b %d %Y'));
print(arduino.readline().strip());

arduino.write("%s\n" % time.strftime('%H:%M:%S'));
print(arduino.readline().strip());
 

Comments are closed.



Nima Jooyandeh facts.