vendredi 2 novembre 2018

python stopwatch in IF ELSE

I try to insert stopwatch in my python code. Code read data from API, and if is value bigger then "3" switch reley to ON ( rassberry Pi3 ). This read every XXX minuts.. all day. I want print time how long it's reley on or off.

while True:
    ts = time.time()
    st = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S') 
    .
    . 
    .
    .
    .
    .
    if highest > 3:
        print("RELEY ON")
        print st
        print # time how long it's on
        GPIO.setmode(GPIO.BOARD)
        GPIO.setup(7, GPIO.OUT)

    else:
        print("RELEY OFF")
        print st
        print # time how long it's off
        GPIO.cleanup()

    time.sleep(60)

I try with this code, but I do not know where to insert it.

import time

start = time.time()
time.sleep(10)
end = time.time()

total = end-start
print total

Thankyou for help!

Aucun commentaire:

Enregistrer un commentaire