Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

python - What am I missing in this relay schedule program?

I am trying to teach myself Python and am having some questions. I understand the general idea, I just need some help fine tuning it. Thank you

#imports
import RPi.GPIO as GPIO
import datetime
import time

#Relay 1 board number
R1 = 26
GPIO.setmode(GPIO.BCM)
GPIO.setup(R1, GPIO.OUT)
h_d = user_input

#start prompts
print("Light schedule")
time.sleep(2)
print("Input hours/day:")                       #Need command to request user input
print("Hours of light per day =", h_d)          #Missing something

#loop
try:
    while True:
        now = datetime.datetime.now().time()
        GPIO.output(R1,GPIO.LOW)
        if now.hour == 7:                        #Daily start time
            GPIO.output(R1, GPIO.HIGH)
            print("Lights ON @")                 #Need it to print only once per occurrence
            print(time.strftime("%-I:%M %p"))    #Something missing
        elif start_time + user_input
            GPIO.output(R1, GPIO.LOW)
            print("Lights OFF @")                #Need it to print only once per occurrence
            print(time.strftime("%-I:%M %p"))    #Something missing
    
finally:
    GPIO.cleanup()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...