#!/usr/bin/python from tentacle_pi.TSL2561 import TSL2561 import time import optparse # Parse command line options p = optparse.OptionParser() p.add_option('--interval', '-i', action='store') p.add_option('--outputfile', '-o', action='store') options, arguments = p.parse_args() if options.interval: intTestInterval = int(options.interval) else: intTestInterval = 3 # Set up the light sensor tsl = TSL2561(0x39,"/dev/i2c-1") tsl.enable() tsl.enable_autogain() tsl.set_time(0x00) # Initialize variables to keep track of time intElapsedTime = 0 # Establish the output data file if options.outputfile: outputfile = open(options.outputfile, 'w+') else: outputfile = open('./testing.txt', 'w+') # Write headers to the output file outputfile.writelines("%s\n" % "ElapsedTime Lux") # Initialize while loop variable currentlux = tsl.lux() try: while currentlux > 20: currentlux = tsl.lux() print "%s %s" % (intElapsedTime, currentlux) outputfile.writelines("%s %s\n" % (intElapsedTime, currentlux)) outputfile.flush intElapsedTime += intTestInterval time.sleep(intTestInterval) finally: tsl.disable() outputfile.close()