请原谅初学者的问题。两周前我才听说过 Python 这个词。
我正在尝试编写一个 python 2.7 脚本,它有两个在 AM 和 PM 中运行的作业。这是一个提醒程序,每天早上 9 点和晚上 9 点都会提醒我。之后它也会每小时提醒我一次。我想尝试找出一种方法,按下 GPIO 按钮将停止当前作业,但允许下一个计划作业发生。这个想法是这两个作业每天都运行,但是按下按钮会说,“停止这个作业并等待下一个预定的作业”。一旦我做了提醒“提醒我”的事情,按下按钮就会停止唠叨。
这是我开始编写的基本代码:
#!/usr/bin/python
import schedule
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
# GPIO 23 set up as input. It is pulled up to stop false signals
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def am_job():
print 'This is the AM job'
def pm_job():
print 'This is the PM job'
schedule.every().day.at("9:00").do(am_job)
schedule.every().day.at("10:00").do(am_job)
schedule.every().day.at("11:00").do(am_job)
schedule.every().day.at("12:00").do(am_job)
schedule.every().day.at("13:00").do(am_job)
schedule.every().day.at("21:00").do(pm_job)
schedule.every().day.at("22:00").do(pm_job)
schedule.every().day.at("23:00").do(pm_job)
# I need to figure out a way that this button press cancels the current job
# but allows the next job to continue.
# Over and over each am and pm
GPIO.add_event_detect(23, GPIO.FALLING, callback="some job name here", bouncetime=400)
try:
while True: # This currently just cycles through all the jobs
schedule.run_pending()
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()
感谢您的任何帮助!