Back to index.
from time import sleep import RPi.GPIO as GPIO import sys #import time import datetime GPIO.setmode(GPIO.BCM) GPIO.setup(16, GPIO.OUT) GPIO.setup(17, GPIO.IN) GPIO.setup(27, GPIO.IN) GPIO.setup(22, GPIO.IN) GPIO.setup(5, GPIO.IN) GPIO.setup(6, GPIO.IN) GPIO.setup(13, GPIO.IN) GPIO.setup(19, GPIO.IN) GPIO.setup(26, GPIO.IN) GPIO.setup(18, GPIO.IN) GPIO.setup(23, GPIO.IN) GPIO.setup(24, GPIO.IN) GPIO.setup(25, GPIO.IN) GPIO.setup(12, GPIO.IN) GPIO.setup(20, GPIO.IN) GPIO.setup(21, GPIO.IN) #GPIO.setup(21, GPIO.IN) file1 = open("data.txt","w") p=GPIO.PWM(16, 100) #ts=time.time() dateT=datetime.datetime.now() #print ts print dateT trigger=0 print "GPIO ready" #file1.write("Start time: {0}".format(ts) + "\n") file1.write("Start time: {0}".format(dateT) + "\n") file1.close() while True: try: if (GPIO.input(17) == False): if (trigger == 0): p.start(50) print "Fibre 1 failed." #tfail=time.time() dateTfail=datetime.datetime.now() #thang=tfail-ts dateThang=dateTfail-dateT #print tfail print dateTfail file1 = open("data.txt","a") #file1.write("Start time: {0}".format(ts) + "\n") #file1.write("Fail time: {0}".format(tfail) + "\n") #file1.write("Hang time: {0}".format(thang) + "\n") file1.write("Fibre 1 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(27) == False): if (trigger == 0): p.start(50) print "Fibre 2 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 2 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(22) == False): if (trigger == 0): p.start(50) print "Fibre 3 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 3 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(5) == False): if (trigger == 0): p.start(50) print "Fibre 4 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 4 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(6) == False): if (trigger == 0): p.start(50) print "Fibre 5 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 5 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(13) == False): if (trigger == 0): p.start(50) print "Fibre 6 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 6 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(19) == False): if (trigger == 0): p.start(50) print "Fibre 7 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 7 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(26) == False): if (trigger == 0): p.start(50) print "Fibre 8 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 8 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(18) == False): if (trigger == 0): p.start(50) print "Fibre 9 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 9 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(23) == False): if (trigger == 0): p.start(50) print "Fibre 10 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 10 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(24) == False): if (trigger == 0): p.start(50) print "Fibre 11 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 11 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(25) == False): if (trigger == 0): p.start(50) print "Fibre 12 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 12 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(12) == False): if (trigger == 0): p.start(50) print "Fibre 13 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 13 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(20) == False): if (trigger == 0): p.start(50) print "Fibre 14 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 14 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 if (GPIO.input(21) == False): if (trigger == 0): p.start(50) print "Fibre 15 failed." dateTfail=datetime.datetime.now() dateThang=dateTfail-dateT print dateTfail file = open("data.txt","a") file1.write("Fibre 15 failed." + "\n") file1.write("Fail time: {0}".format(dateTfail) + "\n") file1.write("Hang time: {0}".format(dateThang) + "\n") file1.write("\n") file1.close() trigger=1 ## if (GPIO.input(21) == False): ## if (trigger == 0): ## p.start(50) ## print "Fibre 16 failed." ## dateTfail=datetime.datetime.now() ## dateThang=dateTfail-dateT ## print dateTfail ## file = open("data.txt","a") ## file1.write("Fibre 16 failed." + "\n") ## file1.write("Fail time: {0}".format(dateTfail) + "\n") ## file1.write("Hang time: {0}".format(dateThang) + "\n") ## file1.write("\n") ## file1.close() ## trigger=1 sleep(0.1) except KeyboardInterrupt: p.stop() GPIO.cleanup() exit()