execute function at a certain time - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: execute function at a certain time (/thread-9189.html) |
execute function at a certain time - StevenLewis - Mar-25-2018 Hi guys I'm new at Python and programming, so I found myself with difficulties at it. As I wrote in the subject, I'm trying to run a function at a certain time. I don't think it can be that difficult but I just don't get it. It seems like "schedule" is the solution but I still couldn't make it. I know that the code is wrong right now but everything I have tried to change ended in an Error. At line 33 I have the function I want to execute at a certain time, after that I want it to move on to the next function. Can you guys give me hint on how to do that? Thanks a lot StevenLewis import Adafruit_DHT import time from rrb3 import * import schedule def test(): humidity1, temperature1 = Adafruit_DHT.read_retry(Adafruit_DHT .AM2302, 4) humidity2, temperature2 = Adafruit_DHT.read_retry(Adafruit_DHT .AM2302, 18) print('Temp_innen={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature1, humidity1)) print('Temp_aussen={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature2, humidity2)) if temperature1 < 19 and temperature2 >21 or temperature1 >23 and temperature2 <21: motortemp() else: timewindow() def motortemp(): rr = RRB3(12, 6) rr.set_led1(0) rr.set_led2(0) rr.forward(2, 1) time.sleep(5) rr.reverse(2, 1) def timewindow(t): # that part at a certain time rr = RRB3(12, 6) rr.set_led1(0) rr.set_led2(0) rr.forward(2, 1) time.sleep(5) rr.reverse(2, 1) print "I'm working...", t return schedule.every().day.at("16:59").do(timewindow,'It is 16:59') while True: schedule.run_pending() time.sleep(60) # wait one minute while True: test() |