1
#import RPi.GPIO as GPIO
from datetime import datetime
from time import strftime
import time

#Setting up GPIO
#GPIO.setmode(GPIO.BCM)
#GPIO.setup(23, GPIO.IN)

#Datetime variables
now_strf = strftime("%I:%M %p")
quest = raw_input("What time would you like to wake up? ")

while True:
    if quest == now_strf:
        print "Ring"
        time.sleep(1)
    else:
        print now_strf
        time.sleep(1)

My problem is it prints "Ring" when i set the alarm for the time it is now, but when I set it for a minute or two later, it doesn't go off. What am I doing wrong?

Leistungsabfall
  • 6,368
  • 7
  • 33
  • 41
dannnyt97
  • 11
  • 1

1 Answers1

0

In your while loop you're comparing two variables, quest and now_strf.

The problem is that now_strf never changes. You need to update now_strf with the current time in every iteration:

while True:
    now_strf = strftime("%I:%M %p")
    if quest == now_strf:
        print "Ring"
        time.sleep(1)
    else:
Leistungsabfall
  • 6,368
  • 7
  • 33
  • 41
  • Thank you so much. I spent way too much time trying to get this to work. Didn't know it was that simple. – dannnyt97 Mar 27 '16 at 20:18