chickenhouse/light_sensor_test.py

20 lines
499 B
Python
Raw Normal View History

2016-03-20 17:32:17 +00:00
#!/usr/bin/python2
from light_sensor import light_sensor
2016-04-07 04:00:06 +00:00
from time import sleep, time
from datetime import datetime
2016-03-20 17:32:17 +00:00
ls = light_sensor(1, 0x23)
while True:
2016-04-07 04:00:06 +00:00
now = datetime.now()
now_str = str(now.year) + "-" + str(now.month) + "-" + str(now.day) + " " + str(now.hour) + ":" + str(now.minute) + ":" + str(now.second)
line = str(int(time())) + " " + now_str + " light: " + str(ls.read()) + " lx."
print line
log = open("light.log", "a")
log.write(line)
log.write("\n")
log.close()
2016-03-20 17:32:17 +00:00
sleep(1)