Skip to content

Instantly share code, notes, and snippets.

@shapr
Created June 24, 2013 03:17
Show Gist options
  • Save shapr/5847557 to your computer and use it in GitHub Desktop.
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
"""
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