Created
June 24, 2013 03:17
-
-
Save shapr/5847557 to your computer and use it in GitHub Desktop.
time now to time alarm, in minutes, less than 24 hours from now
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The Arduino alarm clock asks you for the current time and the time to awake, and then waits that many minutes. | |
""" | |
# mmm, python | |
def hourscalc(hoursnow,minutesnow,hoursalarm,minutesalarm): | |
"""input is (hoursnow,minutesnow) and (hoursalarm,minutesalarm) | |
and should look like hourscalc((00,30),(07,30))""" | |
# NOW AND ALARM ARE IN MINUTES dude! | |
now = (hoursnow * 60) + minutesnow | |
alarm = (hoursalarm * 60) + minutesalarm | |
if (now < alarm): | |
delay = alarm - now | |
elif (now >= alarm): | |
# if alarm is less than now, delay will cross midnight, so do exciting math! | |
delay = (24 * 60) - (now - alarm) | |
return delay |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment