import RPi.GPIO as GPIO import os import sys import datetime import time from time import sleep GPIO.setmode(GPIO.BCM) GPIO.setup(17, GPIO.OUT) runhour = (time.strftime("%H%M%S")) add = 4000 file1 = open("/home/pi/Motor_Running_Project.txt","r",encoding = 'utf-8') f = file1.read(6) print(f) file1.close() intrunhour = int (f) while True: now = int(time.strftime("%H%M%S")) print(now) x = now - intrunhour print(x) if x>=0: GPIO.output(17,GPIO.HIGH) print("program started") time.sleep(900) intrunhour = now + add nextrun = str (intrunhour) file1 = open("/home/pi/Motor_Running_Project.txt","w") file1.write(nextrun) file1.close() print(nextrun) GPIO.output(17,GPIO.LOW) else: print("program not started") GPIO.output(17,GPIO.LOW) GPIO.cleanup()